question

Andres avatar image
0 Likes"
Andres asked Andres commented

SQL Header Group by Query

Hi,

I am making a query to get the best item type product based on certain conditions that must match. The problem is that I am not able to get the row headers with the item type that I am grouping by.

Is there a way to do this?

SQL Group By Example Headers.fsm

Here is the model.

In this example I want the final answer to be "30"


1718059956433.png

FlexSim 24.1.0
sql queriesgroup by
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

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Andres commented

The result of the query is an internal data structure and doesn't have row headers, as far as I know. You will have to add the ModType column to the SELECT clause and treat it as its own column.

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

Andres avatar image Andres commented ·

You are right, that worked. Thanks


Table TableLineModules = Table.query("SELECT [ModType], SUM(CASE WHEN ([Zone] = 3 OR [Zone] = 4) then 1 else 0 END) as [Zone3&4], \

SUM(CASE WHEN ([Zone] = 5 OR [Zone] = 7) then 1 else 0 END) as [Zone5&7], \

COUNT(*) as [Total] \

FROM [Data] \

GROUP BY [ModType] \

ORDER BY [ModType] ASC ");

TableLineModules.cloneTo(Table("TableQuery1"));

0 Likes 0 ·