github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_math_round.test (about) 1 #SELECT, extreme value 2 3 4 select -(0-3),round(-(0-3)), round(9999999999999999999); 5 6 7 select round(5.5),round(-5.5); 8 select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2); 9 10 #INSERT 11 #0.5 MO暂不支持Create select 12 #create table t1 select round(1, 6); 13 #select * from t1; 14 #drop table t1; 15 16 #extreme value 17 select round(111,-10); 18 select round(-5000111000111000155,-1); 19 20 21 select round(15000111000111000155,-1); 22 select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1); 23 select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2); 24 25 select round(1.5, -4294967296), round(1.5, 4294967296); 26 select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808); 27 28 29 #data type 30 CREATE TABLE t1 (a DOUBLE); 31 INSERT INTO t1 VALUES (-1.1), (1.1), 32 (-1.5), (1.5), 33 (-1.9), (1.9), 34 (-2.1), (2.1), 35 (-2.5), (2.5), 36 (-2.9), (2.9), 37 (-1e16 - 0.5), (1e16 + 0.5), 38 (-1e16 - 1.5), (1e16 + 1.5); 39 SELECT a, ROUND(a) FROM t1; 40 DROP TABLE t1; 41 42 #data type 43 -- @bvt:issue#2302 44 CREATE TABLE t1(f1 DECIMAL(22,1)); 45 INSERT INTO t1 VALUES (0),(1); 46 SELECT ROUND(f1, f1) FROM t1; 47 SELECT ROUND(f1, f1) FROM t1 GROUP BY 1; 48 DROP TABLE t1; 49 -- @bvt:issue 50 51 #嵌套 52 #LEAST函数0.5MO暂时不支持 53 #SELECT ROUND(LEAST(15, -4939092, 0.2704), STDDEV('a')); 54 55 56 SELECT ROUND(sin(0.45), cos(0.8)); 57 58 59 #extreme value 60 61 select round(999999999, -9); 62 select round(999999999.0, -9); 63 select round(999999999999999999, -18); 64 select round(999999999999999999.0, -18); 65 -- @bvt:issue 66 67 #嵌套,join 68 CREATE TABLE t1 ( 69 id VARCHAR(80) NOT NULL PRIMARY KEY, 70 sujet VARCHAR(80), 71 motsclefs varchar(255), 72 texte varchar(255) 73 ); 74 INSERT INTO t1 VALUES('123','toto','essai','test'); 75 INSERT INTO t1 VALUES('456','droit','penal','lawyer'); 76 INSERT INTO t1 VALUES('789','aaaaa','bbbbb','cccccc'); 77 CREATE TABLE t2 ( 78 id VARCHAR(255) NOT NULL, 79 author VARCHAR(255) NOT NULL 80 ); 81 INSERT INTO t2 VALUES('123', 'moi'); 82 INSERT INTO t2 VALUES('123', 'lui'); 83 INSERT INTO t2 VALUES('456', 'lui'); 84 #match against 0.5 MO暂不支持 85 #select round(match(t1.texte,t1.sujet,t1.motsclefs) against('droit'),5) 86 #from t1 left join t2 on t2.id=t1.id; 87 #select match(t1.texte,t1.sujet,t1.motsclefs) against('droit' IN BOOLEAN MODE) 88 #from t1 left join t2 on t2.id=t1.id; 89 select round((length(t1.texte)+length(t1.sujet))/length(t2.author)) 90 from t1 left join t2 on t2.id=t1.id; 91 drop table t1; 92 drop table t2; 93 94 #嵌套,extreme value, 科学计算 95 96 select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1); 97 select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2); 98 select round(10000000000000000000, -19); 99 select round(1e0, -309); 100 select round(1e1,308); 101 select round(1e1, 2147483648); 102 select round(1.1e1, 4294967295); 103 select round(1.12e1, 4294967296); 104 select round(1.5, 2147483640); 105 select round(1.5, -2147483649), round(1.5, 2147483648); 106 select round(1.5, -4294967296), round(1.5, 4294967296); 107 select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808); 108 select round(1.5, 18446744073709551615); 109 select round(18446744073709551614, -1); 110 select round(4, -4294967200); 111 112 #比较操作 113 CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER); 114 INSERT INTO t1 (a,b) VALUES (1,2),(1,3),(2,5); 115 SELECT a, 0.1*0+1 r2, SUM(1) r1 FROM t1 WHERE a = 1 GROUP BY a HAVING r1>1 AND r2=1; 116 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a; 117 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a 118 HAVING SUM(1) >0 AND ROUND(sin(100)*10)<0 AND ROUND(sin(100)*10) > -10; 119 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a 120 HAVING SUM(1)>=1 AND (SELECT ROUND(sin(100)*10)>-100 AND ROUND(sin(100)*10) < 0 FROM t1 AS t2 LIMIT 1); 121 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1 122 GROUP BY a HAVING SUM(1)>1 AND ROUND(sin(100)*10)<=2; 123 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1 124 GROUP BY a HAVING SUM(1)>1 AND ROUND(sin(100)*10)<=2 ORDER BY a+r2+r1; 125 SELECT a,SUM(b) FROM t1 WHERE a=1 GROUP BY c; 126 SELECT a*SUM(b) FROM t1 WHERE a=1 GROUP BY c; 127 SELECT SUM(a)*SUM(b) FROM t1 WHERE a=1 GROUP BY c; 128 SELECT a,SUM(b) FROM t1 WHERE a=1 GROUP BY c HAVING a=1; 129 SELECT a AS d,SUM(b) FROM t1 WHERE a=1 GROUP BY c HAVING d=1; 130 SELECT SUM(a)*SUM(b) AS d FROM t1 WHERE a=1 GROUP BY c HAVING d > 0; 131 SELECT a, ROUND(sin(100)*10) r2 FROM t1; 132 SELECT ROUND(sin(100)*10) FROM t1 GROUP BY ROUND(sin(100)*10); 133 DROP TABLE t1; 134 135 #HAVING,比较操作 136 137 CREATE TABLE t1 (i INT, d1 DECIMAL(9,2), d2 DECIMAL(9,2)); 138 INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00), 139 (2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40), 140 (2, 30.40, 30.40), (3, 37.00, 7.40), (3, -29.60, 0.00), 141 (4, 60.00, 15.40), (4, -10.60, 0.00), (4, -34.00, 0.00), 142 (5, 33.00, 0.00), (5, -25.80, 0.00), (5, 0.00, 7.20), 143 (6, 0.00, 0.00), (6, -51.40, 0.00); 144 SELECT i, SUM(d1), SUM(d2) FROM t1 GROUP BY i HAVING SUM(d1) <> SUM(d2); 145 -- @bvt:issue#2302 146 SELECT i, ROUND(SUM(d1), 2), ROUND(SUM(d2), 2) FROM t1 GROUP BY i 147 HAVING ROUND(SUM(d1), 2) <> ROUND(SUM(d2), 2); 148 -- @bvt:issue 149 drop table t1; 150 151 152 #DATA TYPE 153 #0.5 MO的TRUNCATE函数暂不支持 154 -- @bvt:issue#2302 155 CREATE TABLE t1 (qty decimal(16,6) default NULL, dps tinyint(3) unsigned default NULL); 156 INSERT INTO t1 VALUES (1.1325,3); 157 SELECT ROUND(qty,3), dps, ROUND(qty,dps) FROM t1; 158 DROP TABLE t1; 159 -- @bvt:issue 160 161 -- @bvt:issue#2302 162 CREATE TABLE t1( a DECIMAL, b INT ); 163 INSERT INTO t1 VALUES (123456, 40), (123456, 40); 164 #SELECT TRUNCATE( a, b ) AS c FROM t1 ORDER BY c; 165 SELECT ROUND( a, b ) AS c FROM t1 ORDER BY c; 166 SELECT ROUND( a, 100 ) AS c FROM t1 ORDER BY c; 167 CREATE TABLE t2( a DECIMAL, b INT ); 168 INSERT INTO t2 VALUES (123456, 100); 169 #SELECT TRUNCATE( a, b ) AS c FROM t2 ORDER BY c; 170 SELECT ROUND( a, b ) AS c FROM t2 ORDER BY c; 171 CREATE TABLE t3( a DECIMAL, b INT ); 172 INSERT INTO t3 VALUES (123456, 40), (123456, 40); 173 #SELECT TRUNCATE( a, b ) AS c FROM t3 ORDER BY c; 174 SELECT ROUND( a, b ) AS c FROM t3 ORDER BY c; 175 SELECT ROUND( a, 100 ) AS c FROM t3 ORDER BY c; 176 CREATE TABLE t4( a DECIMAL, b INT ); 177 INSERT INTO t4 VALUES (123456, 40), (123456, 40); 178 #SELECT TRUNCATE( a, b ) AS c FROM t4 ORDER BY c; 179 SELECT ROUND( a, b ) AS c FROM t4 ORDER BY c; 180 SELECT ROUND( a, 100 ) AS c FROM t4 ORDER BY c; 181 -- @ignore{ 182 delete from t1; 183 INSERT INTO t1 VALUES (1234567890, 20), (999.99, 5); 184 select round(a,b) as c from t1 order by c; 185 -- @ignore} 186 drop table t1; 187 drop table t2; 188 drop table t3; 189 drop table t4; 190 191 -- @bvt:issue 192 193 -- @bvt:issue#2302 194 CREATE TABLE t1( a DECIMAL(4, 3), b INT ); 195 INSERT INTO t1 VALUES ( 1, 5 ), ( 2, 4 ), ( 3, 3 ), ( 4, 2 ), ( 5, 1 ); 196 SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c; 197 SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c DESC; 198 CREATE TABLE t2 ( a INT, b INT, c DECIMAL(5, 4) ); 199 INSERT INTO t2 VALUES ( 0, 1, 1.2345 ), ( 1, 2, 1.2345 ),( 3, 3, 1.2345 ), ( 2, 4, 1.2345 ); 200 SELECT a, b, MAX(ROUND(c, a)) FROM t2 GROUP BY a, b ORDER BY b; 201 SELECT a, b, ROUND(c, a) FROM t2; 202 CREATE TABLE t3( a INT, b DECIMAL(6, 3) ); 203 INSERT INTO t3 VALUES( 0, 1.5 ); 204 SELECT ROUND( b, a ) FROM t3; 205 CREATE TABLE t4( a INT, b DECIMAL( 12, 0) ); 206 INSERT INTO t4 VALUES( -9, 1.5e9 ); 207 SELECT ROUND( b, a ) FROM t4; 208 CREATE TABLE t5( a INT, b DECIMAL( 13, 12 ) ); 209 INSERT INTO t5 VALUES( 0, 1.5 ); 210 INSERT INTO t5 VALUES( 9, 1.5e-9 ); 211 SELECT ROUND( b, a ) FROM t5; 212 CREATE TABLE t6( a INT ); 213 INSERT INTO t6 VALUES( 6 / 8 ); 214 SELECT * FROM t6; 215 SELECT ROUND(20061108085411.000002); 216 drop table t1; 217 drop table t2; 218 drop table t3; 219 drop table t4; 220 drop table t5; 221 drop table t6; 222 -- @bvt:issue 223 224 -- @bvt:issue#2302 225 CREATE TABLE t5(c1 DECIMAL(16,6), c2 tinyint); 226 INSERT INTO t5 VALUES(1.1325,3); 227 SELECT ROUND(c1,c2) from t5; 228 #select TRUNCATE(c1,c2) FROM t5; 229 DROP TABLE t5; 230 -- @bvt:issue 231 232 #null 233 SELECT ROUND(NULL); 234 235 #算术操作 236 select round(123.54)-round(123.03); 237 238 #WHERE 239 drop table if exists t1; 240 create table t1(a INT, b float); 241 insert into t1 values(12124, -4213.413), (12124, -42413.409); 242 select * from t1 where round(a)=12124; 243 drop table t1; 244 245 #ON CONDITION 246 create table t1(a INT, b float); 247 create table t2(a INT, b float); 248 insert into t1 select round(12124.413), round(-4213.413); 249 insert into t1 select round(12124.123), round(-42413.409); 250 insert into t2 select round(14124.413), round(-4213.413); 251 insert into t2 select round(984798.123), round(-980.409); 252 SELECT t1.a, t2.a FROM t1 JOIN t2 ON (round(t1.b) = round(t2.b)); 253 drop table t1; 254 drop table t2;