diff options
Diffstat (limited to 'mysql-test/r/group_by.result')
-rw-r--r-- | mysql-test/r/group_by.result | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 268f290ddca..30c4d1e4ca1 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -1128,6 +1128,152 @@ id c1 c2 4 2 3 1 5 1 DROP TABLE t1; +# +# Bug#27219: Aggregate functions in ORDER BY. +# +SET @save_sql_mode=@@sql_mode; +SET @@sql_mode='ONLY_FULL_GROUP_BY'; +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT 0); +INSERT INTO t1 (a, b) VALUES (3,3), (2,2), (3,3), (2,2), (3,3), (4,4); +CREATE TABLE t2 SELECT * FROM t1; +SELECT 1 FROM t1 ORDER BY COUNT(*); +1 +1 +SELECT 1 FROM t1 ORDER BY COUNT(*) + 1; +1 +1 +SELECT 1 FROM t1 ORDER BY COUNT(*) + a; +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT 1 FROM t1 ORDER BY COUNT(*), 1; +1 +1 +SELECT 1 FROM t1 ORDER BY COUNT(*), a; +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT 1 FROM t1 ORDER BY SUM(a); +1 +1 +SELECT 1 FROM t1 ORDER BY SUM(a + 1); +1 +1 +SELECT 1 FROM t1 ORDER BY SUM(a) + 1; +1 +1 +SELECT 1 FROM t1 ORDER BY SUM(a), b; +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT a FROM t1 ORDER BY COUNT(b); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2); +a +3 +2 +3 +2 +3 +4 +SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a), t2.a FROM t2); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2 ORDER BY t2.a); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 ORDER BY (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 +WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.a) LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a IN (SELECT t2.a FROM t2 ORDER BY SUM(t1.b)); +a +2 +3 +4 +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a IN (SELECT t2.a FROM t2 ORDER BY t2.a, SUM(t2.b)); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a > ANY (SELECT t2.a FROM t2 ORDER BY t2.a, SUM(t2.b)); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 +WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t1.b)); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(SUM(t1.b) + 1) FROM t2 ORDER BY SUM(t2.a) LIMIT 1); +1 +1 +1 +1 +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(SUM(t1.b) + t2.b) FROM t2 ORDER BY SUM(t2.a) LIMIT 1); +1 +1 +1 +1 +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY SUM(t2.a) LIMIT 1); +1 +1 +1 +1 +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(SUM(t1.b) + 1) FROM t2 ORDER BY t2.a LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(SUM(t1.b) + t2.b) FROM t2 ORDER BY t2.a LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT 1 FROM t1 GROUP BY t1.a +HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY t2.a LIMIT 1); +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +SELECT t1.a FROM t1 +WHERE t1.a = (SELECT t2.a FROM t2 GROUP BY t2.a +ORDER BY SUM(t2.b), SUM(t1.b) LIMIT 1); +a +4 +SELECT t1.a, SUM(t1.b) FROM t1 +WHERE t1.a = (SELECT SUM(t2.b) FROM t2 GROUP BY t2.a +ORDER BY SUM(t2.b), SUM(t1.b) LIMIT 1) +GROUP BY t1.a; +a SUM(t1.b) +4 4 +SELECT t1.a, SUM(t1.b) FROM t1 +WHERE t1.a = (SELECT SUM(t2.b) FROM t2 +ORDER BY SUM(t2.b) + SUM(t1.b) LIMIT 1) +GROUP BY t1.a; +a SUM(t1.b) +SELECT t1.a, SUM(t1.b) FROM t1 +WHERE t1.a = (SELECT SUM(t2.b) FROM t2 +ORDER BY SUM(t2.b + t1.a) LIMIT 1) +GROUP BY t1.a; +a SUM(t1.b) +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING (1, 1) = (SELECT SUM(t1.a), t1.a FROM t2 LIMIT 1); +a +select avg ( +(select +(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt +from t1 as outr order by outr.a limit 1)) +from t1 as most_outer; +avg ( +(select +(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt +from t1 as outr order by outr.a limit 1)) +29.0000 +select avg ( +(select ( +(select sum(outr.a + innr.a) from t1 as innr limit 1)) as tt +from t1 as outr order by count(outr.a) limit 1)) as tt +from t1 as most_outer; +ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause +select (select sum(outr.a + t1.a) from t1 limit 1) as tt from t1 as outr order by outr.a; +tt +29 +29 +35 +35 +35 +41 +SET sql_mode=@save_sql_mode; +DROP TABLE t1, t2; End of 5.0 tests CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), |