~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
DROP TABLE IF EXISTS t1, t2;
2
CREATE TABLE t1 (
3
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
4
gender CHAR(1),
5
name VARCHAR(20)
6
);
7
SELECT SUM(DISTINCT LENGTH(name)) s1 FROM t1;
8
s1
9
NULL
10
INSERT INTO t1 (gender, name) VALUES (NULL, NULL);
11
INSERT INTO t1 (gender, name) VALUES (NULL, NULL);
12
INSERT INTO t1 (gender, name) VALUES (NULL, NULL);
13
SELECT SUM(DISTINCT LENGTH(name)) s1 FROM t1;
14
s1
15
NULL
16
INSERT INTO t1 (gender, name) VALUES ('F', 'Helen'), ('F', 'Anastasia'),
17
('F', 'Katherine'), ('F', 'Margo'), ('F', 'Magdalene'), ('F', 'Mary');
18
CREATE TABLE t2 SELECT name FROM t1;
19
SELECT (SELECT SUM(DISTINCT LENGTH(name)) FROM t1) FROM t2;
20
(SELECT SUM(DISTINCT LENGTH(name)) FROM t1)
21
18
22
18
23
18
24
18
25
18
26
18
27
18
28
18
29
18
30
DROP TABLE t2;
31
INSERT INTO t1 (gender, name) VALUES ('F', 'Eva'), ('F', 'Sofia'),
32
('F', 'Sara'), ('F', 'Golda'), ('F', 'Toba'), ('F', 'Victory'),
33
('F', 'Faina'), ('F', 'Miriam'), ('F', 'Beki'), ('F', 'America'),
34
('F', 'Susan'), ('F', 'Glory'), ('F', 'Priscilla'), ('F', 'Rosmary'),
35
('F', 'Rose'), ('F', 'Margareth'), ('F', 'Elizabeth'), ('F', 'Meredith'),
36
('F', 'Julie'), ('F', 'Xenia'), ('F', 'Zena'), ('F', 'Olga'),
37
('F', 'Brunhilda'), ('F', 'Nataly'), ('F', 'Lara'), ('F', 'Svetlana'),
38
('F', 'Grethem'), ('F', 'Irene');
39
SELECT
40
SUM(DISTINCT LENGTH(name)) s1,
41
SUM(DISTINCT SUBSTRING(NAME, 1, 3)) s2,
42
SUM(DISTINCT LENGTH(SUBSTRING(name, 1, 4))) s3
43
FROM t1;
44
s1	s2	s3
45
42	0	7
46
SELECT
47
SUM(DISTINCT LENGTH(g1.name)) s1,
48
SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2,
49
SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3
50
FROM t1 g1, t1 g2, t1 g3;
51
s1	s2	s3
52
42	0	7
53
SELECT
54
SUM(DISTINCT LENGTH(g1.name)) s1,
55
SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2,
56
SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3
57
FROM t1 g1, t1 g2, t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10));
58
s1	s2	s3
59
42	0	NULL
60
42	0	7
61
42	0	4
62
42	0	4
63
42	0	4
64
42	0	4
65
42	0	4
66
SELECT SQL_BUFFER_RESULT
67
SUM(DISTINCT LENGTH(name)) s1,
68
SUM(DISTINCT SUBSTRING(NAME, 1, 3)) s2,
69
SUM(DISTINCT LENGTH(SUBSTRING(name, 1, 4))) s3
70
FROM t1;
71
s1	s2	s3
72
42	0	7
73
SELECT SQL_BUFFER_RESULT
74
SUM(DISTINCT LENGTH(g1.name)) s1,
75
SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2,
76
SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3
77
FROM t1 g1, t1 g2, t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10));
78
s1	s2	s3
79
42	0	NULL
80
42	0	7
81
42	0	4
82
42	0	4
83
42	0	4
84
42	0	4
85
42	0	4
86
SET @l=1;
87
UPDATE t1 SET name=CONCAT(name, @l:=@l+1);
88
SELECT SUM(DISTINCT RIGHT(name, 1)) FROM t1;
89
SUM(DISTINCT RIGHT(name, 1))
90
45
91
SELECT SUM(DISTINCT id) FROM t1;
92
SUM(DISTINCT id)
93
703
94
SELECT SUM(DISTINCT id % 11) FROM t1;
95
SUM(DISTINCT id % 11)
96
55
97
DROP TABLE t1;