question

Aaditya J avatar image
0 Likes"
Aaditya J asked Aaditya J answered

SQL Query for Conditional Sum

("SELECT SUM(NoOfVehical) FROM MyTable WHERE [City] == 'Delhi') this query is not working for getting the total vehicles in city. Table as under:

City TypeOfVehical NoOfVehical
Delhi Sedan
Mumbai Sedan
Chennai Sedan
Kolkata Sedan
Bengaluru Sedan
Chennai Hatchback
Kolkata Hatchback
Bengaluru Hatchback
Delhi Hatchback
Mumbai Hatchback
Delhi SUV
Mumbai SUV
Chennai SUV
Kolkata SUV
Bengaluru SUV
Chennai Truck
Kolkata Truck
Bengaluru Truck
Delhi Truck
Mumbai Truck
FlexSim 18.2.0
querysql queryconditional
· 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.

Aaditya J avatar image Aaditya J commented ·

Add any number of cars in last table, I dont know why the numbers are not visible

0 Likes 0 ·
Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

I could not replicate the issue. Here is a model that worked for me. Run the script in the script window to test the query.

workingquery.fsm


workingquery.fsm (16.7 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.

Aaditya J avatar image
0 Likes"
Aaditya J answered

It is working in the model that you shared, but for me its not working. I dont know the reason :(

5 |100000

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

Aaditya J avatar image
0 Likes"
Aaditya J answered

I did find one bug in that, if your column name starts with Number value it throws error, we should have column name starting with Text. e.g. "1_City" will throw error while "City" will execute the code.

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.