1
by brian
clean slate |
1 |
drop table if exists t1; |
2 |
create table t1(n1 int, n2 int, s char(20), vs varchar(20), t text); |
|
3 |
insert into t1 values (1,11, 'one','eleven', 'eleven'), |
|
4 |
(1,11, 'one','eleven', 'eleven'), |
|
5 |
(2,11, 'two','eleven', 'eleven'), |
|
6 |
(2,12, 'two','twevle', 'twelve'), |
|
7 |
(2,13, 'two','thirteen', 'foo'), |
|
8 |
(2,13, 'two','thirteen', 'foo'), |
|
9 |
(2,13, 'two','thirteen', 'bar'), |
|
10 |
(NULL,13, 'two','thirteen', 'bar'), |
|
11 |
(2,NULL, 'two','thirteen', 'bar'), |
|
12 |
(2,13, NULL,'thirteen', 'bar'), |
|
13 |
(2,13, 'two',NULL, 'bar'), |
|
14 |
(2,13, 'two','thirteen', NULL); |
|
15 |
select distinct n1 from t1; |
|
16 |
n1
|
|
17 |
1
|
|
18 |
2
|
|
19 |
NULL
|
|
20 |
select count(distinct n1) from t1; |
|
21 |
count(distinct n1) |
|
22 |
2
|
|
23 |
select distinct n2 from t1; |
|
24 |
n2
|
|
25 |
11
|
|
26 |
12
|
|
27 |
13
|
|
28 |
NULL
|
|
29 |
select count(distinct n2) from t1; |
|
30 |
count(distinct n2) |
|
31 |
3
|
|
32 |
select distinct s from t1; |
|
33 |
s
|
|
34 |
one
|
|
35 |
two
|
|
36 |
NULL
|
|
37 |
select count(distinct s) from t1; |
|
38 |
count(distinct s) |
|
39 |
2
|
|
40 |
select distinct vs from t1; |
|
41 |
vs
|
|
42 |
eleven
|
|
43 |
twevle
|
|
44 |
thirteen
|
|
45 |
NULL
|
|
46 |
select count(distinct vs) from t1; |
|
47 |
count(distinct vs) |
|
48 |
3
|
|
49 |
select distinct t from t1; |
|
50 |
t
|
|
51 |
eleven
|
|
52 |
twelve
|
|
53 |
foo
|
|
54 |
bar
|
|
55 |
NULL
|
|
56 |
select count(distinct t) from t1; |
|
57 |
count(distinct t) |
|
58 |
4
|
|
59 |
select distinct n1,n2 from t1; |
|
60 |
n1 n2 |
|
61 |
1 11 |
|
62 |
2 11 |
|
63 |
2 12 |
|
64 |
2 13 |
|
65 |
NULL 13 |
|
66 |
2 NULL |
|
67 |
select count(distinct n1,n2) from t1; |
|
68 |
count(distinct n1,n2) |
|
69 |
4
|
|
70 |
select distinct n1,s from t1; |
|
71 |
n1 s |
|
72 |
1 one |
|
73 |
2 two |
|
74 |
NULL two |
|
75 |
2 NULL |
|
76 |
select count(distinct n1,s) from t1; |
|
77 |
count(distinct n1,s) |
|
78 |
2
|
|
79 |
select distinct s,n1,vs from t1; |
|
80 |
s n1 vs |
|
81 |
one 1 eleven |
|
82 |
two 2 eleven |
|
83 |
two 2 twevle |
|
84 |
two 2 thirteen |
|
85 |
two NULL thirteen |
|
86 |
NULL 2 thirteen |
|
87 |
two 2 NULL |
|
88 |
select count(distinct s,n1,vs) from t1; |
|
89 |
count(distinct s,n1,vs) |
|
90 |
4
|
|
91 |
select distinct s,t from t1; |
|
92 |
s t |
|
93 |
one eleven |
|
94 |
two eleven |
|
95 |
two twelve |
|
96 |
two foo |
|
97 |
two bar |
|
98 |
NULL bar |
|
99 |
two NULL |
|
100 |
select count(distinct s,t) from t1; |
|
101 |
count(distinct s,t) |
|
102 |
5
|
|
103 |
select count(distinct n1), count(distinct n2) from t1; |
|
104 |
count(distinct n1) count(distinct n2) |
|
105 |
2 3 |
|
106 |
select count(distinct n2), n1 from t1 group by n1; |
|
107 |
count(distinct n2) n1 |
|
108 |
1 NULL |
|
109 |
1 1 |
|
110 |
3 2 |
|
111 |
drop table t1; |
|
112 |
create table t1 (n int default NULL); |
|
113 |
flush status; |
|
114 |
select count(distinct n) from t1; |
|
115 |
count(distinct n) |
|
116 |
5000
|
|
117 |
show status like 'Created_tmp_disk_tables'; |
|
118 |
Variable_name Value |
|
119 |
Created_tmp_disk_tables 0 |
|
120 |
drop table t1; |
|
121 |
create table t1 (s text); |
|
122 |
flush status; |
|
123 |
select count(distinct s) from t1; |
|
124 |
count(distinct s) |
|
125 |
5000
|
|
126 |
show status like 'Created_tmp_disk_tables'; |
|
127 |
Variable_name Value |
|
128 |
Created_tmp_disk_tables 1 |
|
129 |
drop table t1; |