sql query

sql query

wang_w2
Not applicable
834 Views
3 Replies
Message 1 of 4

sql query

wang_w2
Not applicable

[ FlexSim 18.2.3 ]

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

0 Likes
Accepted solutions (1)
835 Views
3 Replies
Replies (3)
Message 2 of 4

JordanLJohnson
Autodesk
Autodesk

You need a WHERE statement, not an if statement:

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


Jordan Johnson
Principal Software Engineer
>

Message 3 of 4

manuel_s4
Not applicable
Accepted solution

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.

0 Likes
Message 4 of 4

wang_w2
Not applicable

than you all it works well