question

Kamil KS avatar image
0 Likes"
Kamil KS asked Kamil KS commented

How to create a subquery in the query?

Hello,

I have written the SQL code below. It works fine but it needs to copy the Table Data to Global Table test using cloneTo().

Object buffer = model.find(token.ZalAdr);
Table Data = Table.query("SELECT Bin, ROW_NUMBER() AS NrRow FROM $1 AS Distance",
						buffer.labels["Default"]);	
Data.cloneTo("test");
token.SKU = string.fromNum(token.SKU);		
Table Result = Table.query("SELECT * FROM test AS R, Biny AS B \
							WHERE \
							SKU = $1.SKU \
							AND R.Bin = B.Bin \
							ORDER BY \
							Data ASC, Field ASC, NrRow ASC", token);
token.BinName = Result[1][1];

1. Is it possible to create a subquery (Table Data) using a $ alias in the Table result?

Something like this (not working):

Object buffer = model.find(token.ZalAdr);
token.SKU = string.fromNum(token.SKU);
Table Result = Table.query("SELECT * FROM $1.query("SELECT Bin, ROW_NUMBER() AS NrRow FROM $1 AS Distance", buffer.labels["Default"]) AS R, Biny AS B \
WHERE \
SKU = $2.SKU \
AND R.Bin = B.Bin \
ORDER BY \
Data ASC, Field ASC, NrRow ASC", Table, token);
token.BinName = Result[1][1];

2. Is it possible to refer directly to the Table Data without using cloneTo()?

Unfortuanately, I am not allowed to publish the simulation model.

FlexSim 19.0.7
sql
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

·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Kamil KS commented

1. It sounds like you are asking about a nested query. You can write query code like this:

SELECT ColA, ColB FROM (
	SELECT ColC AS ColA, ColD AS ColB FROM GlobalTable1
) ORDER BY ColA

2. In a query, you can't query a current query result. But I think the nested query will solve your problem.

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

Kamil KS avatar image Kamil KS commented ·

Thank you very mych for your help, I am also struggling with this example:

Table Result2 = Table.query("SELECT Bin, Rotacja, Content FROM Biny \
			WHERE \
			[Rotacja] == $1.rotacja \
			ORDER BY CONTENT \
			CASE Rotacja WHEN 'A' THEN DESC \
			ELSE ASC END", token);

Is it possible to create such a CASE statement in Flexsim?

0 Likes 0 ·

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.