~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/having.test

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
#              select list and TEXT field 
82
82
#
83
83
 
84
 
CREATE TABLE t1 (
 
84
CREATE TEMPORARY TABLE t1 (
85
85
  `id` bigint NOT NULL default '0',
86
86
  `description` text
87
87
) ENGINE=MyISAM;
88
88
 
89
 
CREATE TABLE t2 (
 
89
CREATE TEMPORARY TABLE t2 (
90
90
  `id` bigint NOT NULL default '0',
91
91
  `description` varchar(20)
92
92
) ENGINE=MyISAM;
94
94
INSERT INTO t1  VALUES (1, 'test');
95
95
INSERT INTO t2 VALUES (1, 'test');
96
96
 
97
 
CREATE TABLE t3 (
 
97
CREATE TEMPORARY TABLE t3 (
98
98
  `id`       bigint NOT NULL default '0',
99
99
  `order_id` bigint NOT NULL default '0'
100
100
) ENGINE=MyISAM;
207
207
select count(*) as count_col1 from t1 group by col1 having col1 = 10;
208
208
select count(*) as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
209
209
select count(*) from t1 group by col2 having col2 = 'hello';
210
 
--error 1054
 
210
--error ER_BAD_FIELD_ERROR
211
211
select count(*) from t1 group by col2 having col1 = 10;
212
212
select col1 as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
213
213
select col1 as count_col1 from t1 as tmp1 group by col1 having count_col1 = 10;
221
221
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having count_col1 = 10;
222
222
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col2 = 'hello';
223
223
select col1 as count_col1,col2 as group_col2 from t1 as tmp1 group by col1,col2 having group_col2 = 'hello';
224
 
--error 1064
 
224
--error ER_PARSE_ERROR
225
225
select sum(col1) as co12 from t1 group by col2 having col2 10; 
226
226
select sum(col1) as co2, count(col2) as cc from t1 group by col1 having col1 =10; 
227
 
--error 1054
 
227
--error ER_BAD_FIELD_ERROR
228
228
select t2.col2 from t2 group by t2.col1, t2.col2 having t1.col1 <= 10;
229
229
 
230
230
 
273
273
 
274
274
# nested queries with HAVING, inner having column resolved in outer FROM clause
275
275
# the outer having column is not referenced in GROUP BY which results in an error
276
 
--error 1054
 
276
--error ER_BAD_FIELD_ERROR
277
277
select t1.col1 from t1
278
278
where t1.col2 in 
279
279
      (select t2.col2 from t2 
302
302
# correlated subqueries - inner having column 't1.col2' resolves to
303
303
# the outer FROM clause, which cannot be used because the outer query
304
304
# is grouped
305
 
--error 1054
 
305
--error ER_BAD_FIELD_ERROR
306
306
select sum(col1) from t1
307
307
group by col_t1
308
308
having col_t1 in (select sum(t2.col1) from t2
318
318
#
319
319
# queries with joins and ambiguous column names
320
320
#
321
 
--error 1052
 
321
--error ER_NON_UNIQ_ERROR
322
322
select t1.col1, t2.col1 from t1, t2 where t1.col1 = t2.col1
323
323
group by t1.col1, t2.col1 having col1 = 2;
324
324
 
325
 
--error 1052
 
325
--error ER_NON_UNIQ_ERROR
326
326
select t1.col1*10+t2.col1 from t1,t2 where t1.col1=t2.col1
327
327
group by t1.col1, t2.col1 having col1 = 2;
328
328
 
352
352
 
353
353
select count(s1) from t1 group by s1 having s1*0=0;
354
354
 
 
355
--error ER_NON_UNIQ_ERROR
355
356
select * from t1 a, t1 b group by a.s1 having s1 is null;
356
357
# ANSI requires: 0 rows
357
358
# MySQL returns: