You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query: "SELECT category, group_concat(name ORDER BY (SELECT COUNT(*) FROM test_data t2 WHERE t2.category = test_data.category AND t2.age < test_data.age)) FROM test_data GROUP BY category ORDER BY category",
Query: "SELECT category, group_concat(name ORDER BY (SELECT MAX(age) FROM test_data t2 WHERE t2.id <= test_data.id)) FROM test_data GROUP BY category ORDER BY category",
Query: "SELECT category, group_concat(name ORDER BY (SELECT COUNT(*) FROM test_data t2 WHERE t2.category = test_data.category AND t2.age < test_data.age)) FROM test_data GROUP BY category ORDER BY category",
Query: "SELECT category, group_concat(name ORDER BY (SELECT MAX(age) FROM test_data t2 WHERE t2.id <= test_data.id)) FROM test_data GROUP BY category ORDER BY category",
Query: "SELECT category_id, GROUP_CONCAT(name ORDER BY (SELECT rating FROM suppliers WHERE suppliers.id = products.supplier_id) DESC) FROM products GROUP BY category_id ORDER BY category_id",
Query: "SELECT category_id, GROUP_CONCAT(DISTINCT supplier_id ORDER BY (SELECT rating FROM suppliers WHERE suppliers.id = products.supplier_id)) FROM products GROUP BY category_id",
2830
+
Expected: []sql.Row{{1, "2,1"}, {2, "3"}},
2831
+
},
2832
+
{
2833
+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT priority FROM categories WHERE categories.id = products.category_id), price) FROM products",
Query: "SELECT category_id, GROUP_CONCAT(name ORDER BY (SELECT AVG(price) FROM products p2 WHERE p2.category_id = products.category_id) DESC, name) FROM products GROUP BY category_id ORDER BY category_id",
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT name, value FROM test_table t2 WHERE t2.id = test_table.id)) FROM test_table",
2852
+
ExpectedErr: sql.ErrInvalidOperandColumns,
2853
+
},
2854
+
{
2855
+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT value FROM test_table)) FROM test_table",
2856
+
ExpectedErr: sql.ErrExpectedSingleRow,
2857
+
},
2858
+
},
2859
+
},
2860
+
{
2861
+
Name: "Group Concat Subquery ORDER BY Additional Edge Cases",
2862
+
Dialect: "mysql",
2863
+
SetUpScript: []string{
2864
+
"CREATE TABLE complex_test (id INT PRIMARY KEY, name VARCHAR(50), value INT, category VARCHAR(10), created_at DATE)",
2865
+
"INSERT INTO complex_test VALUES (1, 'Alpha', 100, 'X', '2023-01-01')",
2866
+
"INSERT INTO complex_test VALUES (2, 'Beta', 50, 'Y', '2023-01-15')",
2867
+
"INSERT INTO complex_test VALUES (3, 'Gamma', 75, 'X', '2023-02-01')",
2868
+
"INSERT INTO complex_test VALUES (4, 'Delta', 25, 'Z', '2023-02-15')",
2869
+
"INSERT INTO complex_test VALUES (5, 'Epsilon', 90, 'Y', '2023-03-01')",
2870
+
},
2871
+
Assertions: []ScriptTestAssertion{
2872
+
{
2873
+
// Test with subquery returning NULL values
2874
+
Query: "SELECT category, GROUP_CONCAT(name ORDER BY (SELECT CASE WHEN complex_test.value > 80 THEN NULL ELSE complex_test.value END)) FROM complex_test GROUP BY category ORDER BY category",
// Test with correlated subquery using multiple tables
2879
+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT COUNT(*) FROM complex_test c2 WHERE c2.category = complex_test.category AND c2.value > complex_test.value)) FROM complex_test",
// Test with subquery using aggregate functions with HAVING
2884
+
Query: "SELECT category, GROUP_CONCAT(name ORDER BY (SELECT AVG(value) FROM complex_test c2 WHERE c2.id <= complex_test.id HAVING AVG(value) > 50) DESC) FROM complex_test GROUP BY category ORDER BY category",
Query: "SELECT GROUP_CONCAT(DISTINCT category ORDER BY (SELECT SUM(value) FROM complex_test c2 WHERE c2.category = complex_test.category) DESC SEPARATOR '|') FROM complex_test",
2890
+
Expected: []sql.Row{{"X|Y|Z"}},
2891
+
},
2892
+
{
2893
+
// Test with nested subqueries
2894
+
Query: "SELECT GROUP_CONCAT(name ORDER BY (SELECT COUNT(*) FROM complex_test c2 WHERE c2.value > (SELECT MIN(value) FROM complex_test c3 WHERE c3.category = complex_test.category))) FROM complex_test",
0 commit comments