~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to mysql-test/r/group_by.result

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
1129
1129
4       2       3
1130
1130
1       5       1
1131
1131
DROP TABLE t1;
 
1132
#
 
1133
# Bug#27219: Aggregate functions in ORDER BY.  
 
1134
#
 
1135
SET @save_sql_mode=@@sql_mode;
 
1136
SET @@sql_mode='ONLY_FULL_GROUP_BY';
 
1137
CREATE TABLE t1 (a INT, b INT, c INT DEFAULT 0);
 
1138
INSERT INTO t1 (a, b) VALUES (3,3), (2,2), (3,3), (2,2), (3,3), (4,4);
 
1139
CREATE TABLE t2 SELECT * FROM t1;
 
1140
SELECT 1 FROM t1 ORDER BY COUNT(*);
 
1141
1
 
1142
1
 
1143
SELECT 1 FROM t1 ORDER BY COUNT(*) + 1;
 
1144
1
 
1145
1
 
1146
SELECT 1 FROM t1 ORDER BY COUNT(*) + a;
 
1147
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1148
SELECT 1 FROM t1 ORDER BY COUNT(*), 1;
 
1149
1
 
1150
1
 
1151
SELECT 1 FROM t1 ORDER BY COUNT(*), a;
 
1152
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1153
SELECT 1 FROM t1 ORDER BY SUM(a);
 
1154
1
 
1155
1
 
1156
SELECT 1 FROM t1 ORDER BY SUM(a + 1);
 
1157
1
 
1158
1
 
1159
SELECT 1 FROM t1 ORDER BY SUM(a) + 1;
 
1160
1
 
1161
1
 
1162
SELECT 1 FROM t1 ORDER BY SUM(a), b;
 
1163
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1164
SELECT a FROM t1 ORDER BY COUNT(b);
 
1165
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1166
SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2);
 
1167
a
 
1168
3
 
1169
2
 
1170
3
 
1171
2
 
1172
3
 
1173
4
 
1174
SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a), t2.a FROM t2);
 
1175
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1176
SELECT t1.a FROM t1 ORDER BY (SELECT SUM(t2.a) FROM t2 ORDER BY t2.a);
 
1177
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1178
SELECT t1.a FROM t1 ORDER BY (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1);
 
1179
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1180
SELECT t1.a FROM t1
 
1181
WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.b) LIMIT 1);
 
1182
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1183
SELECT t1.a FROM t1 GROUP BY t1.a
 
1184
HAVING t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t2.a) LIMIT 1);
 
1185
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1186
SELECT t1.a FROM t1 GROUP BY t1.a
 
1187
HAVING t1.a IN (SELECT t2.a FROM t2 ORDER BY SUM(t1.b));
 
1188
a
 
1189
2
 
1190
3
 
1191
4
 
1192
SELECT t1.a FROM t1 GROUP BY t1.a
 
1193
HAVING t1.a IN (SELECT t2.a FROM t2 ORDER BY t2.a, SUM(t2.b));
 
1194
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1195
SELECT t1.a FROM t1 GROUP BY t1.a
 
1196
HAVING t1.a > ANY (SELECT t2.a FROM t2 ORDER BY t2.a, SUM(t2.b));
 
1197
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1198
SELECT t1.a FROM t1
 
1199
WHERE t1.a = (SELECT t2.a FROM t2 ORDER BY SUM(t1.b));
 
1200
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1201
SELECT 1 FROM t1 GROUP BY t1.a
 
1202
HAVING (SELECT AVG(SUM(t1.b) + 1) FROM t2 ORDER BY SUM(t2.a) LIMIT 1);
 
1203
1
 
1204
1
 
1205
1
 
1206
1
 
1207
SELECT 1 FROM t1 GROUP BY t1.a
 
1208
HAVING (SELECT AVG(SUM(t1.b) + t2.b) FROM t2 ORDER BY SUM(t2.a) LIMIT 1);
 
1209
1
 
1210
1
 
1211
1
 
1212
1
 
1213
SELECT 1 FROM t1 GROUP BY t1.a
 
1214
HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY SUM(t2.a) LIMIT 1);
 
1215
1
 
1216
1
 
1217
1
 
1218
1
 
1219
SELECT 1 FROM t1 GROUP BY t1.a
 
1220
HAVING (SELECT AVG(SUM(t1.b) + 1) FROM t2 ORDER BY t2.a LIMIT 1);
 
1221
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1222
SELECT 1 FROM t1 GROUP BY t1.a
 
1223
HAVING (SELECT AVG(SUM(t1.b) + t2.b) FROM t2 ORDER BY t2.a LIMIT 1);
 
1224
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1225
SELECT 1 FROM t1 GROUP BY t1.a
 
1226
HAVING (SELECT AVG(t1.b + t2.b) FROM t2 ORDER BY t2.a LIMIT 1);
 
1227
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1228
SELECT t1.a FROM t1 
 
1229
WHERE t1.a = (SELECT t2.a FROM t2 GROUP BY t2.a
 
1230
ORDER BY SUM(t2.b), SUM(t1.b) LIMIT 1);
 
1231
a
 
1232
4
 
1233
SELECT t1.a, SUM(t1.b) FROM t1 
 
1234
WHERE t1.a = (SELECT SUM(t2.b) FROM t2 GROUP BY t2.a
 
1235
ORDER BY SUM(t2.b), SUM(t1.b) LIMIT 1)
 
1236
GROUP BY t1.a;
 
1237
a       SUM(t1.b)
 
1238
4       4
 
1239
SELECT t1.a, SUM(t1.b) FROM t1 
 
1240
WHERE t1.a = (SELECT SUM(t2.b) FROM t2
 
1241
ORDER BY SUM(t2.b) + SUM(t1.b) LIMIT 1)
 
1242
GROUP BY t1.a;
 
1243
a       SUM(t1.b)
 
1244
SELECT t1.a, SUM(t1.b) FROM t1 
 
1245
WHERE t1.a = (SELECT SUM(t2.b) FROM t2
 
1246
ORDER BY SUM(t2.b + t1.a) LIMIT 1)
 
1247
GROUP BY t1.a;
 
1248
a       SUM(t1.b)
 
1249
SELECT t1.a FROM t1 GROUP BY t1.a
 
1250
HAVING (1, 1) = (SELECT SUM(t1.a), t1.a FROM t2 LIMIT 1);
 
1251
a
 
1252
select avg (
 
1253
(select
 
1254
(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt
 
1255
from t1 as outr order by outr.a limit 1))
 
1256
from t1 as most_outer;
 
1257
avg (
 
1258
(select
 
1259
(select sum(outr.a + innr.a) from t1 as innr limit 1) as tt
 
1260
from t1 as outr order by outr.a limit 1))
 
1261
29.0000
 
1262
select avg (
 
1263
(select (
 
1264
(select sum(outr.a + innr.a) from t1 as innr limit 1)) as tt
 
1265
from t1 as outr order by count(outr.a) limit 1)) as tt
 
1266
from t1 as most_outer;
 
1267
ERROR 42000: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
 
1268
select (select sum(outr.a + t1.a) from t1 limit 1) as tt from t1 as outr order by outr.a;
 
1269
tt
 
1270
29
 
1271
29
 
1272
35
 
1273
35
 
1274
35
 
1275
41
 
1276
SET sql_mode=@save_sql_mode;
 
1277
DROP TABLE t1, t2;
1132
1278
End of 5.0 tests
1133
1279
CREATE TABLE t1 (a INT, b INT,
1134
1280
PRIMARY KEY (a),