~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
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
50
FROM t1 g1 CROSS JOIN t1 g2 CROSS JOIN t1 g3;
1 by brian
clean slate
51
s1	s2	s3
52
42	0	7
53
SELECT
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
54
SQL_BIG_RESULT
1 by brian
clean slate
55
SUM(DISTINCT LENGTH(g1.name)) s1,
56
SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2,
57
SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
58
FROM t1 g1 CROSS JOIN t1 g2 CROSS JOIN t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10));
1 by brian
clean slate
59
s1	s2	s3
60
42	0	NULL
61
42	0	7
62
42	0	4
63
42	0	4
64
42	0	4
65
42	0	4
66
42	0	4
67
SELECT SQL_BUFFER_RESULT
68
SUM(DISTINCT LENGTH(name)) s1,
69
SUM(DISTINCT SUBSTRING(NAME, 1, 3)) s2,
70
SUM(DISTINCT LENGTH(SUBSTRING(name, 1, 4))) s3
71
FROM t1;
72
s1	s2	s3
73
42	0	7
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
74
SELECT SQL_BIG_RESULT
1 by brian
clean slate
75
SUM(DISTINCT LENGTH(g1.name)) s1,
76
SUM(DISTINCT SUBSTRING(g2.name, 1, 3)) s2,
77
SUM(DISTINCT LENGTH(SUBSTRING(g3.name, 1, 4))) s3
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
78
FROM t1 g1 CROSS JOIN t1 g2 CROSS JOIN t1 g3 GROUP BY LENGTH(SUBSTRING(g3.name, 5, 10));
1 by brian
clean slate
79
s1	s2	s3
80
42	0	NULL
81
42	0	7
82
42	0	4
83
42	0	4
84
42	0	4
85
42	0	4
86
42	0	4
87
SET @l=1;
88
UPDATE t1 SET name=CONCAT(name, @l:=@l+1);
89
SELECT SUM(DISTINCT RIGHT(name, 1)) FROM t1;
90
SUM(DISTINCT RIGHT(name, 1))
91
45
92
SELECT SUM(DISTINCT id) FROM t1;
93
SUM(DISTINCT id)
94
703
95
SELECT SUM(DISTINCT id % 11) FROM t1;
96
SUM(DISTINCT id % 11)
97
55
98
DROP TABLE t1;