github.com/matrixorigin/matrixone@v0.7.0/test/distributed/cases/function/func_math_round.result (about) 1 select -(0-3),round(-(0-3)), round(9999999999999999999); 2 -(0-3) round(-(0-3)) round(9999999999999999999) 3 3 3 9999999999999999999 4 select round(5.5),round(-5.5); 5 round(5.5) round(-5.5) 6 6 -6 7 select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2); 8 round(5.64,1) round(5.64,2) round(5.64,-1) round(5.64,-2) 9 5.6 5.64 10 0 10 select round(111,-10); 11 round(111,-10) 12 0 13 select round(-5000111000111000155,-1); 14 round(-5000111000111000155, -1) 15 -5000111000111000160 16 select round(15000111000111000155,-1); 17 round(15000111000111000155, -1) 18 15000111000111000160 19 select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1); 20 Data truncation: data out of range: data type uint64, 21 select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2); 22 Data truncation: data out of range: data type uint64, 23 select round(1.5, -4294967296), round(1.5, 4294967296); 24 round(1.5, -4294967296) round(1.5, 4294967296) 25 0 1.5 26 select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808); 27 Data truncation: data out of range: data type int64, 28 CREATE TABLE t1 (a DOUBLE); 29 INSERT INTO t1 VALUES (-1.1), (1.1), 30 (-1.5), (1.5), 31 (-1.9), (1.9), 32 (-2.1), (2.1), 33 (-2.5), (2.5), 34 (-2.9), (2.9), 35 (-1e16 - 0.5), (1e16 + 0.5), 36 (-1e16 - 1.5), (1e16 + 1.5); 37 SELECT a, ROUND(a) FROM t1; 38 a ROUND(a) 39 -1.1 -1.0 40 1.1 1.0 41 -1.5 -2.0 42 1.5 2.0 43 -1.9 -2.0 44 1.9 2.0 45 -2.1 -2.0 46 2.1 2.0 47 -2.5 -2.0 48 2.5 2.0 49 -2.9 -3.0 50 2.9 3.0 51 -1.0E16 -1.0E16 52 1.0E16 1.0E16 53 -1.0000000000000002E16 -1.0000000000000002E16 54 1.0000000000000002E16 1.0000000000000002E16 55 DROP TABLE t1; 56 CREATE TABLE t1(f1 DECIMAL(22,1)); 57 INSERT INTO t1 VALUES (0),(1); 58 SELECT ROUND(f1, f1) FROM t1; 59 ROUND(f1, f1) 60 0.0 61 1.0 62 SELECT ROUND(f1, f1) FROM t1 GROUP BY 1; 63 ROUND(f1, f1) 64 0.0 65 1.0 66 DROP TABLE t1; 67 SELECT ROUND(sin(0.45), cos(0.8)); 68 ROUND(sin(0.45), cos(0.8)) 69 0.4 70 select round(999999999, -9); 71 round(999999999, -9) 72 1000000000 73 select round(999999999.0, -9); 74 round(999999999.0, -9) 75 1000000000 76 select round(999999999999999999, -18); 77 round(999999999999999999, -18) 78 1000000000000000000 79 select round(999999999999999999.0, -18); 80 round(999999999999999999.0, -18) 81 1000000000000000000 82 CREATE TABLE t1 ( 83 id VARCHAR(80) NOT NULL PRIMARY KEY, 84 sujet VARCHAR(80), 85 motsclefs varchar(255), 86 texte varchar(255) 87 ); 88 INSERT INTO t1 VALUES('123','toto','essai','test'); 89 INSERT INTO t1 VALUES('456','droit','penal','lawyer'); 90 INSERT INTO t1 VALUES('789','aaaaa','bbbbb','cccccc'); 91 CREATE TABLE t2 ( 92 id VARCHAR(255) NOT NULL, 93 author VARCHAR(255) NOT NULL 94 ); 95 INSERT INTO t2 VALUES('123', 'moi'); 96 INSERT INTO t2 VALUES('123', 'lui'); 97 INSERT INTO t2 VALUES('456', 'lui'); 98 select round((length(t1.texte)+length(t1.sujet))/length(t2.author)) 99 from t1 left join t2 on t2.id=t1.id; 100 round((length(t1.texte)+length(t1.sujet))/length(t2.author)) 101 3 102 3 103 4 104 null 105 drop table t1; 106 drop table t2; 107 select round(cast(-2 as unsigned), 1), round(18446744073709551614, 1), round(-2, 1); 108 Data truncation: data out of range: data type uint64, 109 select round(4, cast(-2 as unsigned)), round(4, 18446744073709551614), round(4, -2); 110 Data truncation: data out of range: data type uint64, 111 select round(10000000000000000000, -19); 112 round(10000000000000000000, -19) 113 10000000000000000000 114 select round(1e0, -309); 115 round(1e0, -309) 116 0.0 117 select round(1e1,308); 118 round(1e1,308) 119 10.0 120 select round(1e1, 2147483648); 121 round(1e1, 2147483648) 122 10.0 123 select round(1.1e1, 4294967295); 124 round(1.1e1, 4294967295) 125 11.0 126 select round(1.12e1, 4294967296); 127 round(1.12e1, 4294967296) 128 11.2 129 select round(1.5, 2147483640); 130 round(1.5, 2147483640) 131 1.5 132 select round(1.5, -2147483649), round(1.5, 2147483648); 133 round(1.5, -2147483649) round(1.5, 2147483648) 134 0 1.5 135 select round(1.5, -4294967296), round(1.5, 4294967296); 136 round(1.5, -4294967296) round(1.5, 4294967296) 137 0 1.5 138 select round(1.5, -9223372036854775808), round(1.5, 9223372036854775808); 139 Data truncation: data out of range: data type int64, 140 select round(1.5, 18446744073709551615); 141 Data truncation: data out of range: data type int64, 142 select round(18446744073709551614, -1); 143 round(18446744073709551614, -1) 144 18446744073709551610 145 select round(4, -4294967200); 146 round(4, -4294967200) 147 0 148 CREATE TABLE t1 (a INTEGER, b INTEGER, c INTEGER); 149 INSERT INTO t1 (a,b) VALUES (1,2),(1,3),(2,5); 150 SELECT a, 0.1*0+1 r2, SUM(1) r1 FROM t1 WHERE a = 1 GROUP BY a HAVING r1>1 AND r2=1; 151 SQL syntax error: column "r1" must appear in the GROUP BY clause or be used in an aggregate function 152 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a; 153 a r2 r1 154 1 -5.0 2 155 2 -5.0 1 156 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a 157 HAVING SUM(1) >0 AND ROUND(sin(100)*10)<0 AND ROUND(sin(100)*10) > -10; 158 a r2 r1 159 1 -5.0 2 160 2 -5.0 1 161 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 GROUP BY a 162 HAVING SUM(1)>=1 AND (SELECT ROUND(sin(100)*10)>-100 AND ROUND(sin(100)*10) < 0 FROM t1 AS t2 LIMIT 1); 163 a r2 r1 164 1 -5.0 2 165 2 -5.0 1 166 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1 167 GROUP BY a HAVING SUM(1)>1 AND ROUND(sin(100)*10)<=2; 168 a r2 r1 169 1 -5.0 2 170 SELECT a, ROUND(sin(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1 171 GROUP BY a HAVING SUM(1)>1 AND ROUND(sin(100)*10)<=2 ORDER BY a+r2+r1; 172 a r2 r1 173 1 -5.0 2 174 SELECT a,SUM(b) FROM t1 WHERE a=1 GROUP BY c; 175 SQL syntax error: column "t1.a" must appear in the GROUP BY clause or be used in an aggregate function 176 SELECT a*SUM(b) FROM t1 WHERE a=1 GROUP BY c; 177 SQL syntax error: column "t1.a" must appear in the GROUP BY clause or be used in an aggregate function 178 SELECT SUM(a)*SUM(b) FROM t1 WHERE a=1 GROUP BY c; 179 sum(a) * sum(b) 180 10 181 SELECT a,SUM(b) FROM t1 WHERE a=1 GROUP BY c HAVING a=1; 182 SQL syntax error: column "t1.a" must appear in the GROUP BY clause or be used in an aggregate function 183 SELECT a AS d,SUM(b) FROM t1 WHERE a=1 GROUP BY c HAVING d=1; 184 SQL syntax error: column "d" must appear in the GROUP BY clause or be used in an aggregate function 185 SELECT SUM(a)*SUM(b) AS d FROM t1 WHERE a=1 GROUP BY c HAVING d > 0; 186 SQL syntax error: column "d" must appear in the GROUP BY clause or be used in an aggregate function 187 SELECT a, ROUND(sin(100)*10) r2 FROM t1; 188 a r2 189 1 -5.0 190 1 -5.0 191 2 -5.0 192 SELECT ROUND(sin(100)*10) FROM t1 GROUP BY ROUND(sin(100)*10); 193 round(sin(100) * 10) 194 -5.0 195 DROP TABLE t1; 196 CREATE TABLE t1 (i INT, d1 DECIMAL(9,2), d2 DECIMAL(9,2)); 197 INSERT INTO t1 VALUES (1, 101.40, 21.40), (1, -80.00, 0.00), 198 (2, 0.00, 0.00), (2, -13.20, 0.00), (2, 59.60, 46.40), 199 (2, 30.40, 30.40), (3, 37.00, 7.40), (3, -29.60, 0.00), 200 (4, 60.00, 15.40), (4, -10.60, 0.00), (4, -34.00, 0.00), 201 (5, 33.00, 0.00), (5, -25.80, 0.00), (5, 0.00, 7.20), 202 (6, 0.00, 0.00), (6, -51.40, 0.00); 203 SELECT i, SUM(d1), SUM(d2) FROM t1 GROUP BY i HAVING SUM(d1) <> SUM(d2); 204 i sum(d1) sum(d2) 205 6 -51.40 0 206 SELECT i, ROUND(SUM(d1), 2), ROUND(SUM(d2), 2) FROM t1 GROUP BY i 207 HAVING ROUND(SUM(d1), 2) <> ROUND(SUM(d2), 2); 208 i sum(d1) sum(d2) 209 6 -51.40 0 210 drop table t1; 211 CREATE TABLE t1 (qty decimal(16,6) default NULL, dps tinyint(3) unsigned default NULL); 212 INSERT INTO t1 VALUES (1.1325,3); 213 SELECT ROUND(qty,3), dps, ROUND(qty,dps) FROM t1; 214 ROUND(qty,3) dps ROUND(qty,dps) 215 1.133 3 1.133000 216 DROP TABLE t1; 217 CREATE TABLE t1( a DECIMAL, b INT ); 218 INSERT INTO t1 VALUES (123456, 40), (123456, 40); 219 SELECT ROUND( a, b ) AS c FROM t1 ORDER BY c; 220 c 221 123456 222 123456 223 SELECT ROUND( a, 100 ) AS c FROM t1 ORDER BY c; 224 c 225 123456 226 123456 227 CREATE TABLE t2( a DECIMAL, b INT ); 228 INSERT INTO t2 VALUES (123456, 100); 229 SELECT ROUND( a, b ) AS c FROM t2 ORDER BY c; 230 c 231 123456 232 CREATE TABLE t3( a DECIMAL, b INT ); 233 INSERT INTO t3 VALUES (123456, 40), (123456, 40); 234 SELECT ROUND( a, b ) AS c FROM t3 ORDER BY c; 235 c 236 123456 237 123456 238 SELECT ROUND( a, 100 ) AS c FROM t3 ORDER BY c; 239 c 240 123456 241 123456 242 CREATE TABLE t4( a DECIMAL, b INT ); 243 INSERT INTO t4 VALUES (123456, 40), (123456, 40); 244 SELECT ROUND( a, b ) AS c FROM t4 ORDER BY c; 245 c 246 123456 247 123456 248 SELECT ROUND( a, 100 ) AS c FROM t4 ORDER BY c; 249 c 250 123456 251 123456 252 delete from t1; 253 INSERT INTO t1 VALUES (1234567890, 20), (999.99, 5); 254 select round(a,b) as c from t1 order by c; 255 c 256 1000 257 1234567890 258 drop table t1; 259 drop table t2; 260 drop table t3; 261 drop table t4; 262 CREATE TABLE t1( a DECIMAL(4, 3), b INT ); 263 INSERT INTO t1 VALUES ( 1, 5 ), ( 2, 4 ), ( 3, 3 ), ( 4, 2 ), ( 5, 1 ); 264 SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c; 265 a b c 266 1.000 5 1.000 267 2.000 4 2.000 268 3.000 3 3.000 269 4.000 2 4.000 270 5.000 1 5.000 271 SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c DESC; 272 a b c 273 5.000 1 5.000 274 4.000 2 4.000 275 3.000 3 3.000 276 2.000 4 2.000 277 1.000 5 1.000 278 CREATE TABLE t2 ( a INT, b INT, c DECIMAL(5, 4) ); 279 INSERT INTO t2 VALUES ( 0, 1, 1.2345 ), ( 1, 2, 1.2345 ),( 3, 3, 1.2345 ), ( 2, 4, 1.2345 ); 280 SELECT a, b, MAX(ROUND(c, a)) FROM t2 GROUP BY a, b ORDER BY b; 281 a b MAX(ROUND(c, a)) 282 0 1 1.0000 283 1 2 1.2000 284 3 3 1.2350 285 2 4 1.2300 286 SELECT a, b, ROUND(c, a) FROM t2; 287 a b ROUND(c, a) 288 0 1 1.0000 289 1 2 1.2000 290 3 3 1.2350 291 2 4 1.2300 292 CREATE TABLE t3( a INT, b DECIMAL(6, 3) ); 293 INSERT INTO t3 VALUES( 0, 1.5 ); 294 SELECT ROUND( b, a ) FROM t3; 295 ROUND( b, a ) 296 2.000 297 CREATE TABLE t4( a INT, b DECIMAL( 12, 0) ); 298 INSERT INTO t4 VALUES( -9, 1.5e9 ); 299 SELECT ROUND( b, a ) FROM t4; 300 ROUND( b, a ) 301 2000000000 302 CREATE TABLE t5( a INT, b DECIMAL( 13, 12 ) ); 303 INSERT INTO t5 VALUES( 0, 1.5 ); 304 INSERT INTO t5 VALUES( 9, 1.5e-9 ); 305 SELECT ROUND( b, a ) FROM t5; 306 ROUND( b, a ) 307 2.000000000000 308 2.000E-9 309 CREATE TABLE t6( a INT ); 310 INSERT INTO t6 VALUES( 6 / 8 ); 311 SELECT * FROM t6; 312 a 313 1 314 SELECT ROUND(20061108085411.000002); 315 ROUND(20061108085411.000002) 316 20061108085411 317 drop table t1; 318 drop table t2; 319 drop table t3; 320 drop table t4; 321 drop table t5; 322 drop table t6; 323 CREATE TABLE t5(c1 DECIMAL(16,6), c2 tinyint); 324 INSERT INTO t5 VALUES(1.1325,3); 325 SELECT ROUND(c1,c2) from t5; 326 ROUND(c1,c2) 327 1.133000 328 DROP TABLE t5; 329 SELECT ROUND(NULL); 330 ROUND(NULL) 331 null 332 select round(123.54)-round(123.03); 333 round(123.54)-round(123.03) 334 1 335 drop table if exists t1; 336 create table t1(a INT, b float); 337 insert into t1 values(12124, -4213.413), (12124, -42413.409); 338 select * from t1 where round(a)=12124; 339 a b 340 12124 -4213.41 341 12124 -42413.4 342 drop table t1; 343 create table t1(a INT, b float); 344 create table t2(a INT, b float); 345 insert into t1 select round(12124.413), round(-4213.413); 346 insert into t1 select round(12124.123), round(-42413.409); 347 insert into t2 select round(14124.413), round(-4213.413); 348 insert into t2 select round(984798.123), round(-980.409); 349 SELECT t1.a, t2.a FROM t1 JOIN t2 ON (round(t1.b) = round(t2.b)); 350 a a 351 12124 14124 352 drop table t1; 353 drop table t2;