1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Implementation of WL#1972 "Evaluate HAVING before SELECT select-list"

mysql-test/r/having.result:
  Added test of WL#1972
mysql-test/t/having.test:
  Added test of WL#1972
sql/item.cc:
  Name resolution for the HAVING clause searches non-aggregated GROUP BY columns.
This commit is contained in:
unknown
2004-10-28 17:31:26 +03:00
parent 4c06b4aed7
commit 637c08d7cc
3 changed files with 462 additions and 67 deletions

View File

@ -128,3 +128,119 @@ id description c
1 test 0
2 test2 0
drop table t1,t2,t3;
drop table if exists wl1972;
create table wl1972 (
col1 int,
col2 varchar(5) character set latin1 collate latin1_bin)
engine=innodb;
insert into wl1972 values(10,'hello');
insert into wl1972 values(20,'hello');
insert into wl1972 values(30,'hello');
insert into wl1972 values(10,'bye');
insert into wl1972 values(10,'sam');
insert into wl1972 values(10,'bob');
select count(*) from wl1972 group by col1 having col1 = 10;
count(*)
4
select count(*) as count_col1 from wl1972 group by col1 having col1 = 10;
count_col1
4
select count(*) as count_col1 from wl1972 as t1 group by col1 having col1 = 10;
count_col1
4
select count(*) from wl1972 group by col2 having col2 = 'hello';
count(*)
3
select count(*) from wl1972 group by col2 having col1 = 10;
ERROR 42S22: Unknown column 'col1' in 'having clause'
select col1 as count_col1 from wl1972 as t1 group by col1 having col1 = 10;
count_col1
10
select col1 as count_col1 from wl1972 as t1 group by col1 having count_col1 = 10;
count_col1
10
select col1 as count_col1 from wl1972 as t1 group by count_col1 having col1 = 10;
count_col1
10
select col1 as count_col1 from wl1972 as t1 group by count_col1 having count_col1 = 10;
count_col1
10
select col1 as count_col1,col2 from wl1972 as t1 group by col1,col2 having col1 = 10;
count_col1 col2
10 bob
10 bye
10 hello
10 sam
select col1 as count_col1,col2 from wl1972 as t1 group by col1,col2 having count_col1 = 10;
count_col1 col2
10 bob
10 bye
10 hello
10 sam
select col1 as count_col1,col2 from wl1972 as t1 group by col1,col2 having col2 = 'hello';
count_col1 col2
10 hello
20 hello
30 hello
select col1 as count_col1,col2 as group_col2 from wl1972 as t1
group by col1,col2 having group_col2 = 'hello';
count_col1 group_col2
10 hello
20 hello
30 hello
select sum(col1) as co12 from wl1972 group by col2 having col2 10;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10' at line 1
select sum(col1) as co2, count(col2) as cc from wl1972 group by col1 having col1 =10;
co2 cc
40 4
select t1.col1 from wl1972 as t1 where t1.col2 in
(select t2.col2 from wl1972 as t2
group by t2.col1,t2.col2 having t2.col1<=10);
col1
10
20
30
10
10
10
select t1.col1 from wl1972 as t1 where t1.col2 in
(select t2.col2 from wl1972 as t2
group by t2.col1,t2.col2 having t2.col1<=
(select min(t3.col1) from wl1972 as t3));
col1
10
20
30
10
10
10
drop table wl1972;
create table wl1972 (s1 int);
insert into wl1972 values (1),(2),(3);
select count(*) from wl1972 group by s1 having s1 is null;
count(*)
select s1*0 as s1 from wl1972 group by s1 having s1 <> 0;
s1
select s1*0 from wl1972 group by s1 having s1 = 0;
s1*0
select s1 from wl1972 group by 1 having 1 = 0;
s1
select count(s1) from wl1972 group by s1 having count(1+1)=2;
count(s1)
select count(s1) from wl1972 group by s1 having s1*0=0;
count(s1)
1
1
1
select * from wl1972 a, wl1972 b group by a.s1 having s1 is null;
ERROR 23000: Column 's1' in having clause is ambiguous
drop table wl1972;
create table wl1972 (s1 char character set latin1 collate latin1_german1_ci);
insert into wl1972 values ('ü'),('y');
Warnings:
Warning 1265 Data truncated for column 's1' at row 1
select s1,count(s1) from wl1972
group by s1 collate latin1_swedish_ci having s1 = 'y';
s1 count(s1)
y 1
drop table wl1972;