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().

  1. Object buffer = model.find(token.ZalAdr);
  2. Table Data = Table.query("SELECT Bin, ROW_NUMBER() AS NrRow FROM $1 AS Distance",
  3. buffer.labels["Default"]);
  4. Data.cloneTo("test");
  5. token.SKU = string.fromNum(token.SKU);
  6. Table Result = Table.query("SELECT * FROM test AS R, Biny AS B \
  7. WHERE \
  8. SKU = $1.SKU \
  9. AND R.Bin = B.Bin \
  10. ORDER BY \
  11. Data ASC, Field ASC, NrRow ASC", token);
  12. 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):

  1. Object buffer = model.find(token.ZalAdr);
  2. token.SKU = string.fromNum(token.SKU);
  3. 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 \
  4. WHERE \
  5. SKU = $2.SKU \
  6. AND R.Bin = B.Bin \
  7. ORDER BY \
  8. Data ASC, Field ASC, NrRow ASC", Table, token);
  9. 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:

  1. SELECT ColA, ColB FROM (
  2. SELECT ColC AS ColA, ColD AS ColB FROM GlobalTable1
  3. ) 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.