mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / r / count_distinct.result
blob804bc1f4788c6adab8e732cd9b5444fea776695d
1 drop table if exists t1,t2,t3;
2 create table t1 (libname varchar(21) not null, city text, primary key (libname));
3 create table t2 (isbn varchar(21) not null, author text, title text, primary key (isbn));
4 create table t3 (isbn varchar(21) not null, libname varchar(21) not null, quantity int ,primary key (isbn,libname));
5 insert into t2 values ('001','Daffy','A duck''s life');
6 insert into t2 values ('002','Bugs','A rabbit\'s life');
7 insert into t2 values ('003','Cowboy','Life on the range');
8 insert into t2 values ('000','Anonymous','Wanna buy this book?');
9 insert into t2 values ('004','Best Seller','One Heckuva book');
10 insert into t2 values ('005','EveryoneBuys','This very book');
11 insert into t2 values ('006','San Fran','It is a san fran lifestyle');
12 insert into t2 values ('007','BerkAuthor','Cool.Berkley.the.book');
13 insert into t3 values('000','New York Public Libra','1');
14 insert into t3 values('001','New York Public Libra','2');
15 insert into t3 values('002','New York Public Libra','3');
16 insert into t3 values('003','New York Public Libra','4');
17 insert into t3 values('004','New York Public Libra','5');
18 insert into t3 values('005','New York Public Libra','6');
19 insert into t3 values('006','San Fransisco Public','5');
20 insert into t3 values('007','Berkeley Public1','3');
21 insert into t3 values('007','Berkeley Public2','3');
22 insert into t3 values('001','NYC Lib','8');
23 insert into t1 values ('New York Public Libra','New York');
24 insert into t1 values ('San Fransisco Public','San Fran');
25 insert into t1 values ('Berkeley Public1','Berkeley');
26 insert into t1 values ('Berkeley Public2','Berkeley');
27 insert into t1 values ('NYC Lib','New York');
28 select t2.isbn,city,t1.libname,count(t1.libname) as a from t3 left join t1 on t3.libname=t1.libname left join t2 on t3.isbn=t2.isbn group by city,t1.libname;
29 isbn    city    libname a
30 007     Berkeley        Berkeley Public1        1
31 007     Berkeley        Berkeley Public2        1
32 000     New York        New York Public Libra   6
33 001     New York        NYC Lib 1
34 006     San Fran        San Fransisco Public    1
35 select t2.isbn,city,t1.libname,count(distinct t1.libname) as a from t3 left join t1 on t3.libname=t1.libname left join t2 on t3.isbn=t2.isbn group by city having count(distinct t1.libname) > 1;
36 isbn    city    libname a
37 007     Berkeley        Berkeley Public1        2
38 000     New York        New York Public Libra   2
39 select t2.isbn,city,t1.libname,count(distinct t1.libname) as a from t3 left join t1 on t3.libname=t1.libname left join t2 on t3.isbn=t2.isbn group by city having count(distinct concat(t1.libname,'a')) > 1;
40 isbn    city    libname a
41 007     Berkeley        Berkeley Public1        2
42 000     New York        New York Public Libra   2
43 select t2.isbn,city,@bar:=t1.libname,count(distinct t1.libname) as a
44 from t3 left join t1 on t3.libname=t1.libname left join t2
45 on t3.isbn=t2.isbn group by city having count(distinct
46 t1.libname) > 1;
47 isbn    city    @bar:=t1.libname        a
48 007     Berkeley        Berkeley Public1        2
49 000     New York        New York Public Libra   2
50 SELECT @bar;
51 @bar
52 Berkeley Public2
53 select t2.isbn,city,concat(@bar:=t1.libname),count(distinct t1.libname) as a
54 from t3 left join t1 on t3.libname=t1.libname left join t2
55 on t3.isbn=t2.isbn group by city having count(distinct
56 t1.libname) > 1;
57 isbn    city    concat(@bar:=t1.libname)        a
58 007     Berkeley        Berkeley Public1        2
59 000     New York        New York Public Libra   2
60 SELECT @bar;
61 @bar
62 Berkeley Public2
63 drop table t1, t2, t3;
64 create table t1 (f1 int);
65 insert into t1 values (1);
66 create table t2 (f1 int,f2 int);
67 select t1.f1,count(distinct t2.f2),count(distinct 1,NULL) from t1 left join t2 on t1.f1=t2.f1 group by t1.f1;
68 f1      count(distinct t2.f2)   count(distinct 1,NULL)
69 1       0       0
70 drop table t1,t2;
71 create table t1 (f int);
72 select count(distinct f) from t1;
73 count(distinct f)
75 drop table t1;
76 create table t1 (a char(3), b char(20), primary key (a, b));
77 insert into t1 values ('ABW', 'Dutch'), ('ABW', 'English');
78 select count(distinct a) from t1 group by b;
79 count(distinct a)
82 drop table t1;
83 create table t1 (f1 int, f2 int);
84 insert into t1 values (0,1),(1,2);
85 select count(distinct if(f1,3,f2)) from t1;
86 count(distinct if(f1,3,f2))
88 drop table t1;