question

wang W2 avatar image
0 Likes"
wang W2 Suspended asked wang W2 Suspended commented

sql query

hello

I want to count The number of rows corresponding to the same type ,like graph below,.Type3 has there rows, how can i count this row num to use sql query code?

like code below:

double result=Table.query("SELECT COUNT(if(type=3,true,null)) FORM ItemList1")[1][1];

but it wont work.

could you enlighten me please?thank you.

无标题.png

FlexSim 18.2.3
query
无标题.png (26.3 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Manuel Sinco avatar image
0 Likes"
Manuel Sinco answered wang W2 Suspended commented

Hello @wang W2,

You can use the same query but instead of saving everything as a double you can save it as a Table and then count the rows in it. Try this:

int TypeNumber = 3; 
Table ResultQ = Table.query("SELECT * FROM ItemList1 WHERE Type = $1", TypeNumber); 
int Rows = ResultQ.numRows;

You can change the value of TypeNumber to whatever number you want. Depending on the values that you have with the same value the table will increase its size in rows, but you'll obtain the necessary value always.

Hope it works.

Manuel.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

wang W2 avatar image wang W2 commented ·

than you all it works well

1 Like 1 ·
Jordan Johnson avatar image
2 Likes"
Jordan Johnson answered

You need a WHERE statement, not an if statement:

double result=Table.query("SELECT COUNT(*) FROM ItemList1 WHERE Type = 3")[1][1];
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.