-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sql
116 lines (86 loc) · 3.67 KB
/
test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
This file is part of MariaDB Statistics Library.
MariaDB Statistics Library is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
MariaDB Statistics Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with MariaDB Statistics Library.
If not, see <https://www.gnu.org/licenses/>.
*/
-- weighted_avg()
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
-- Expected Result: NULL
SELECT weighted_avg(i, 1) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
-- Expected Result: 1
INSERT INTO t VALUES (1, 1), (NULL, 1);
SELECT weighted_avg(i, 1) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
-- Expected Result: 1
INSERT INTO t VALUES (1, 1), (1, NULL);
SELECT weighted_avg(i, 1) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1), (5), (2), (4);
-- Expected Result: 0
SELECT weighted_avg(i, 0) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1), (5), (2), (4);
-- Expected Result: 3
SELECT weighted_avg(i, 1) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (-1), (-5), (-2), (-4);
-- Expected Result: -3
SELECT weighted_avg(i, 1) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
INSERT INTO t VALUES (1, 1), (3, 1), (10, 0);
-- Expected Result: 2
SELECT weighted_avg(i, w) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
INSERT INTO t VALUES (1, 3), (3, 1);
-- Expected Result: 1.5
SELECT weighted_avg(i, w) FROM t;
-- geometric_mean()
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
-- Expected Result: NULL
SELECT geometric_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1.05), (1.03), (1.06), (1.02), (1.04);
-- Expected Result: 1.0399
SELECT geometric_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1.05), (NULL), (1.03), (1.06), (1.02), (1.04);
-- Expected Result: NULL
SELECT geometric_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1.05), (0), (1.03), (1.06), (1.02), (1.04);
-- Expected Error: ERROR 30001 (45000): One of the observations is zero or less
SELECT geometric_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1.05), (-0.1), (1.03), (1.06), (1.02), (1.04);
-- Expected Error: ERROR 30001 (45000): One of the observations is zero or less
SELECT geometric_mean(i) FROM t;
-- weighted_geometric_mean()
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
-- Expected Result: NULL
SELECT weighted_geometric_mean(i, w) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT, w FLOAT);
INSERT INTO t VALUES (1, 2), (2, 5), (3, 6), (4, 4), (5, 3);
-- Expected Result: 2.77748
SELECT weighted_geometric_mean(i, w) FROM t;
-- harmonic_mean()
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
-- Expected Result: NULL
SELECT harmonic_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1);
-- Expected Result: 1
SELECT harmonic_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (0);
-- Expected Error: ERROR 30001 (45000): One of the observations is zero or less
SELECT harmonic_mean(i) FROM t;
CREATE OR REPLACE TEMPORARY TABLE t (i FLOAT);
INSERT INTO t VALUES (1), (3), (5);
-- Expected Result: 1.95652
SELECT harmonic_mean(i) FROM t;