~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/t/count_distinct.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Problem with count(distinct)
 
3
#
 
4
 
 
5
--disable_warnings
 
6
drop table if exists t1,t2,t3;
 
7
--enable_warnings
 
8
 
 
9
create table t1 (libname varchar(21) not null, city text, primary key (libname));
 
10
create table t2 (isbn varchar(21) not null, author text, title text, primary key (isbn));
 
11
create table t3 (isbn varchar(21) not null, libname varchar(21) not null, quantity int ,primary key (isbn,libname));
 
12
insert into t2 values ('001','Daffy','A duck''s life');
 
13
insert into t2 values ('002','Bugs','A rabbit\'s life');
 
14
insert into t2 values ('003','Cowboy','Life on the range');
 
15
insert into t2 values ('000','Anonymous','Wanna buy this book?');
 
16
insert into t2 values ('004','Best Seller','One Heckuva book');
 
17
insert into t2 values ('005','EveryoneBuys','This very book');
 
18
insert into t2 values ('006','San Fran','It is a san fran lifestyle');
 
19
insert into t2 values ('007','BerkAuthor','Cool.Berkley.the.book');
 
20
insert into t3 values('000','New York Public Libra','1');
 
21
insert into t3 values('001','New York Public Libra','2');
 
22
insert into t3 values('002','New York Public Libra','3');
 
23
insert into t3 values('003','New York Public Libra','4');
 
24
insert into t3 values('004','New York Public Libra','5');
 
25
insert into t3 values('005','New York Public Libra','6');
 
26
insert into t3 values('006','San Fransisco Public','5');
 
27
insert into t3 values('007','Berkeley Public1','3');
 
28
insert into t3 values('007','Berkeley Public2','3');
 
29
insert into t3 values('001','NYC Lib','8');
 
30
insert into t1 values ('New York Public Libra','New York');
 
31
insert into t1 values ('San Fransisco Public','San Fran');
 
32
insert into t1 values ('Berkeley Public1','Berkeley');
 
33
insert into t1 values ('Berkeley Public2','Berkeley');
 
34
insert into t1 values ('NYC Lib','New York');
 
35
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;
 
36
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;
 
37
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;
 
38
drop table t1, t2, t3;
 
39
 
 
40
#
 
41
# Problem with LEFT JOIN
 
42
#
 
43
 
 
44
create table t1 (f1 int);
 
45
insert into t1 values (1);
 
46
create table t2 (f1 int,f2 int);
 
47
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;
 
48
drop table t1,t2;
 
49
 
 
50
 
 
51
#
 
52
# Empty tables
 
53
#
 
54
create table t1 (f int);
 
55
select count(distinct f) from t1;
 
56
drop table t1;
 
57
 
 
58
# End of 4.1 tests
 
59
 
 
60
#
 
61
# Bug #6515
 
62
#
 
63
 
 
64
create table t1 (a char(3), b char(20), primary key (a, b));
 
65
insert into t1 values ('ABW', 'Dutch'), ('ABW', 'English');
 
66
select count(distinct a) from t1 group by b;
 
67
drop table t1;
 
68
 
 
69
#
 
70
# Bug #9593 "The combination of COUNT, DISTINCT and CONCAT 
 
71
#            seems to lock the server"
 
72
# Bug appears only on Windows system
 
73
#
 
74
 
 
75
create table t1 (f1 int, f2 int);
 
76
insert into t1 values (0,1),(1,2);
 
77
select count(distinct if(f1,3,f2)) from t1;
 
78
drop table t1;
 
79