question

Sung Kim avatar image
0 Likes"
Sung Kim asked Sung Kim commented

query command for "group by" sql construct

I use query command to have a list of unique values from a table. The "Data" and "LIST" tables are prepared, and here is my script.

query("SELECT myValue from Data GROUP BY myValue");

dumpquery(reftable("LIST"), 1);

This script generates a list but not "grouping by". It just list all the values from the myValue column just like we do "SELECT myValue from Data");

What did I miss? I believe FlexSim supports the "GROUP BY" according to the help reference, doesn't it?

Thanks much for your help in advance.

FlexSim 16.2.0
query
fxnbd.png (15.5 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.

1 Answer

Ralf Gruber avatar image
0 Likes"
Ralf Gruber answered Sung Kim commented

Sung,

to sort a query you need the ORDER BY command:

query("SELECT * FROM Data ORDER BY myValue");

If instead of sorting you wanted aggregated information about your two unique values 1 and 2, this one would give you the sum for each:

query("SELECT myValue, SUM(myValue) FROM Data GROUP BY myValue");

That should do it.

· 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.

Sung Kim avatar image Sung Kim commented ·

Thanks, @Ralf!

Even though I don't need the aggregated information, your query still gives me what I need, which is the list of distinct values from "myValue" in the first column.

Thanks for the tip!

0 Likes 0 ·