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:

CityTypeOfVehicalNoOfVehical
DelhiSedan
MumbaiSedan
ChennaiSedan
KolkataSedan
BengaluruSedan
ChennaiHatchback
KolkataHatchback
BengaluruHatchback
DelhiHatchback
MumbaiHatchback
DelhiSUV
MumbaiSUV
ChennaiSUV
KolkataSUV
BengaluruSUV
ChennaiTruck
KolkataTruck
BengaluruTruck
DelhiTruck
MumbaiTruck
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.

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

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.

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.