<?xml version="1.0"?>

<sqlgg>
 <stmt name="create_test_table1" sql="CREATE TABLE test_table1 (&#x0A;    col1 INT,&#x0A;    col2 INT,&#x0A;    col3 DECIMAL(10, 2)&#x0A;)" category="DDL" kind="create" target="test_table1" cardinality="0">
  <in/>
  <out/>
 </stmt>
 <stmt name="create_test_table2" sql="CREATE TABLE test_table2 (&#x0A;    col4 INT,&#x0A;    col5 VARCHAR(50)&#x0A;)" category="DDL" kind="create" target="test_table2" cardinality="0">
  <in/>
  <out/>
 </stmt>
 <stmt name="create_test22" sql="CREATE TABLE test22 (&#x0A;    col_id INT PRIMARY KEY,&#x0A;    col_value DECIMAL(10, 2),&#x0A;    col_group VARCHAR(100)&#x0A;)" category="DDL" kind="create" target="test22" cardinality="0">
  <in/>
  <out/>
 </stmt>
 <stmt name="select_3" sql="WITH cte1 AS (&#x0A;    SELECT col2, AVG(col3) AS col6&#x0A;    FROM test_table1&#x0A;    GROUP BY col2&#x0A;),&#x0A;cte2 AS (&#x0A;    SELECT t2.col4, t2.col5, c1.col6&#x0A;    FROM test_table2 t2&#x0A;    JOIN cte1 c1 ON t2.col4 = c1.col2&#x0A;    WHERE c1.col6 &gt; @some_value&#x0A;)&#x0A;SELECT *&#x0A;FROM cte2" category="DQL" kind="select" cardinality="n">
  <in>
   <value name="some_value" type="Float"/>
  </in>
  <out>
   <value name="col4" type="Int" nullable="true"/>
   <value name="col5" type="Text" nullable="true"/>
   <value name="col6" type="Float" nullable="true"/>
  </out>
 </stmt>
 <stmt name="select_4" sql="SELECT *&#x0A;FROM (&#x0A;    WITH&#x0A;    cte_grouped AS (&#x0A;        SELECT col_group, AVG(col_value) AS avg_value&#x0A;        FROM test22&#x0A;        GROUP BY col_group&#x0A;    ),&#x0A;    cte_counts AS (&#x0A;        SELECT col_group, COUNT(*) AS group_count&#x0A;        FROM test22&#x0A;        GROUP BY col_group&#x0A;    ),&#x0A;    cte_max_values AS (&#x0A;        SELECT col_group, MAX(col_value) AS max_value&#x0A;        FROM test22&#x0A;        GROUP BY col_group&#x0A;    ),&#x0A;    cte_combined AS (&#x0A;        SELECT &#x0A;            g.col_group, &#x0A;            g.avg_value, &#x0A;            c.group_count, &#x0A;            m.max_value&#x0A;        FROM cte_grouped g&#x0A;        JOIN cte_counts c ON g.col_group = c.col_group&#x0A;        JOIN cte_max_values m ON g.col_group = m.col_group&#x0A;    )&#x0A;    SELECT col_group, avg_value, group_count, max_value&#x0A;    FROM cte_combined&#x0A;) AS dt&#x0A;WHERE dt.group_count &gt; 1 AND dt.avg_value &gt; 50.00" category="DQL" kind="select" cardinality="n">
  <in/>
  <out>
   <value name="col_group" type="Text" nullable="true"/>
   <value name="avg_value" type="Float" nullable="true"/>
   <value name="group_count" type="Int"/>
   <value name="max_value" type="Decimal" nullable="true"/>
  </out>
 </stmt>
 <table name="test22">
  <schema>
   <value name="col_id" type="Int"/>
   <value name="col_value" type="Decimal" nullable="true"/>
   <value name="col_group" type="Text" nullable="true"/>
  </schema>
 </table>
 <table name="test_table2">
  <schema>
   <value name="col4" type="Int" nullable="true"/>
   <value name="col5" type="Text" nullable="true"/>
  </schema>
 </table>
 <table name="test_table1">
  <schema>
   <value name="col1" type="Int" nullable="true"/>
   <value name="col2" type="Int" nullable="true"/>
   <value name="col3" type="Decimal" nullable="true"/>
  </schema>
 </table>
</sqlgg>
