github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_aggr_max.test (about) 1 #NULL 2 SELECT max(null); 3 4 #DATATYPE 5 create table t1(a tinyint, b SMALLINT, c bigint, d INT, e BIGINT, f FLOAT, g DOUBLE, h decimal(38,19), i DATE, k datetime, l TIMESTAMP, m char(255), n varchar(255)); 6 insert into t1 values(1, 1, 2, 43, 5, 35.5, 31.133, 14.314, "2012-03-10", "2012-03-12 10:03:12", "2022-03-12 13:03:12", "ab23c", "d5cf"); 7 insert into t1 values(71, 1, 2, 34, 5, 5.5, 341.13, 15.314, "2012-03-22", "2013-03-12 10:03:12", "2032-03-12 13:04:12", "abr23c", "3dcf"); 8 insert into t1 values(1, 1, 21, 4, 54, 53.5, 431.13, 14.394, "2011-03-12", "2015-03-12 10:03:12", "2002-03-12 13:03:12", "afbc", "dct5f"); 9 insert into t1 values(1, 71, 2, 34, 5, 5.5, 31.313, 124.314, "2012-01-12", "2019-03-12 10:03:12", "2013-03-12 13:03:12", "3abd1c", "dcvf"); 10 select max(a) from t1; 11 select max(b) from t1; 12 select max(c) from t1; 13 select max(d) from t1; 14 select max(e) from t1; 15 select max(f) from t1; 16 select max(g) from t1; 17 select max(h) from t1; 18 select max(i) from t1; 19 select max(k) from t1; 20 select max(l) from t1; 21 select max(m) from t1; 22 select max(n) from t1; 23 drop table t1; 24 25 26 #0.5暂不支持time类型 27 #create table t1(a time) 28 #insert into t1 values("10:03:12"); 29 #insert into t1 values("10:03:12"); 30 #insert into t1 values("10:03:12"); 31 #insert into t1 values("10:03:12"); 32 #select max(a) from t1; 33 #drop table t1; 34 35 #EXTREME VALUE, 算术操作 36 select max(99999999999999999.99999); 37 select max(999999999999999933193939.99999); 38 select max(9999999999999999999999999999999999.9999999999999); 39 40 create table t1(a bigint); 41 select max(a) from t1; 42 insert into t1 values(null),(null),(null),(null); 43 select max(a) from t1; 44 insert into t1 values(12417249128419),(124124125124151),(5124125151415),(124125152651515); 45 select max(a) from t1; 46 drop table t1; 47 create table t1 ( a int not null default 1, big bigint ); 48 insert into t1 (big) values (-1),(1234567890167),(92233720368547),(18446744073709515); 49 select * from t1; 50 select min(big),max(big),max(big)-1 from t1; 51 select min(big),max(big),max(big)-1 from t1 group by a; 52 insert into t1 (big) values (184467440737615); 53 select * from t1; 54 select min(big),max(big),max(big)-1 from t1; 55 select min(big),max(big),max(big)-1 from t1 group by a; 56 drop table t1; 57 58 59 #DATA type 60 create table t1 (name char(20) not null); 61 create table t2 (name char(20) not null); 62 insert into t1 values ("å"); 63 insert into t1 values ("ä"); 64 insert into t1 values ("ö"); 65 insert into t2 select * from t1; 66 select * from t1 order by name; 67 select concat_ws(",","*",name,"*") from t1 order by 1; 68 -- @bvt:issue#3344 69 select min(name),min(concat_ws(",","*",name,"*")),max(name),max(concat_ws("*",name,"*")) from t1; 70 -- @bvt:issue 71 drop table t1; 72 drop table t2; 73 74 #HAVING,DISTINCT 75 CREATE TABLE t1 (Fld1 int(11) default NULL,Fld2 int(11) default NULL); 76 INSERT INTO t1 VALUES (1,10),(1,20),(2,NULL),(2,NULL),(3,50); 77 #select Fld1, max(distinct Fld2) as q from t1 group by Fld1 having q is not null; 78 select distinct Fld1, max( Fld2) as q from t1 group by Fld1 having q is not null; 79 select Fld1, max(Fld2) from t1 group by Fld1 having max(Fld2) is not null; 80 select Fld1, max(Fld2) from t1 group by Fld1 having avg(Fld2) is not null; 81 select Fld1, max(Fld2) from t1 group by Fld1 having std(Fld2) is not null; 82 select Fld1, max(Fld2) from t1 group by Fld1 having variance(Fld2) is not null; 83 drop table t1; 84 85 86 87 create table t1 (grp int, a bigint unsigned, c char(10) not null); 88 insert into t1 values (1,1,"a"); 89 insert into t1 values (2,2,"b"); 90 insert into t1 values (2,3,"c"); 91 insert into t1 values (3,4,"E"); 92 insert into t1 values (3,5,"C"); 93 insert into t1 values (3,6,"D"); 94 select sum(a) from t1 where a > 10; 95 select count(distinct a),count(distinct grp) from t1; 96 insert into t1 values (null,null,''); 97 select count(distinct a),count(distinct grp) from t1; 98 create table t2 (grp int, a bigint unsigned, c char(10)); 99 insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp; 100 drop table t1; 101 drop table t2; 102 103 104 105 create table t1 (a1 int, a2 char(3)); 106 insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz'); 107 create table t2(a1 char(3), a2 int, a3 real); 108 select * from t1; 109 -- @bvt:issue#3344 110 select min(a2) from t1; 111 -- @bvt:issue 112 select max(t1.a1), max(t2.a2) from t1, t2; 113 select max(t1.a1) from t1, t2; 114 select max(t2.a2), max(t1.a1) from t1, t2; 115 insert into t2 values('AAA', 10, 0.5); 116 insert into t2 values('BBB', 20, 1.0); 117 select t1.a1, t1.a2, t2.a1, t2.a2 from t1,t2; 118 select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9; 119 select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9; 120 select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10; 121 select max(t1.a2) from t1 left outer join t2 on t1.a1=10; 122 select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=20; 123 select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=10; 124 select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA'; 125 select max(t1.a2),max(t2.a1) from t1 left outer join t2 on t1.a1=10; 126 drop table t1; 127 drop table t2; 128 129 130 CREATE TABLE t1 (a int, b int); 131 select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1; 132 select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; 133 insert into t1 values (1,null); 134 select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; 135 insert into t1 values (1,null); 136 insert into t1 values (2,null); 137 select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; 138 insert into t1 values (2,1); 139 select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; 140 insert into t1 values (3,1); 141 select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; 142 drop table t1; 143 144 145 146 create table t1(a1 char(3) primary key,a2 smallint,a3 char(3),a4 real,a5 date); 147 create table t2(a1 char(3) primary key,a2 char(17),a3 char(2),a4 char(3)); 148 insert into t1 values('AME',0,'SEA',0.100,date'1942-02-19'); 149 insert into t1 values('HBR',1,'SEA',0.085,date'1948-03-05'); 150 insert into t1 values('BOT',2,'SEA',0.085,date'1951-11-29'); 151 insert into t1 values('BMC',3,'SEA',0.085,date'1958-09-08'); 152 insert into t1 values('TWU',0,'LAX',0.080,date'1969-10-05'); 153 insert into t1 values('BDL',0,'DEN',0.080,date'1960-11-27'); 154 insert into t1 values('DTX',1,'NYC',0.080,date'1961-05-04'); 155 insert into t1 values('PLS',1,'WDC',0.075,date'1949-01-02'); 156 insert into t1 values('ZAJ',2,'CHI',0.075,date'1960-06-15'); 157 insert into t1 values('VVV',2,'MIN',0.075,date'1959-06-28'); 158 insert into t1 values('GTM',3,'DAL',0.070,date'1977-09-23'); 159 insert into t1 values('SSJ',null,'CHI',null,date'1974-03-19'); 160 insert into t1 values('KKK',3,'ATL',null,null); 161 insert into t1 values('XXX',null,'MIN',null,null); 162 insert into t1 values('WWW',1,'LED',null,null); 163 164 insert into t2 values('TKF','Seattle','WA','AME'); 165 insert into t2 values('LCC','Los Angeles','CA','TWU'); 166 insert into t2 values('DEN','Denver','CO','BDL'); 167 insert into t2 values('SDC','San Diego','CA','TWU'); 168 insert into t2 values('NOL','New Orleans','LA','GTM'); 169 insert into t2 values('LAK','Los Angeles','CA','TWU'); 170 insert into t2 values('AAA','AAA','AA','AME'); 171 172 173 select * from t1; 174 select * from t2; 175 select min(a1) from t1; 176 select max(a4) from t1; 177 select min(a5), max(a5) from t1; 178 select min(a3) from t1 where a2 = 2; 179 select min(a1), max(a1) from t1 where a4 = 0.080; 180 select min(t1.a5), max(t2.a3) from t1, t2; 181 select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA'; 182 select min(a1) from t1 where a1 > 'KKK'; 183 select min(a1) from t1 where a1 >= 'KKK'; 184 select max(a3) from t1 where a2 = 2 and a3 < 'SEA'; 185 select max(a5) from t1 where a5 < date'1970-01-01'; 186 select max(a3) from t1 where a2 is null; 187 select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q'; 188 select min(a1), max(a1) from t1 where a1 between 'A' and 'P'; 189 select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN'; 190 select max(a3) from t1 where a3 = 'MIN' and a2 = 2; 191 select max(a3) from t1 where a3 = 'DEN' and a2 = 2; 192 select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA'; 193 select max(a3) from t1 where a2 is null and a2 = 2; 194 select max(a2) from t1 where a2 >= 1; 195 select min(a3) from t1 where a2 = 2 and a3 < 'SEA'; 196 select min(a3) from t1 where a2 = 4; 197 select min(a3) from t1 where a2 = 2 and a3 > 'SEA'; 198 select (min(a4)+max(a4))/2 from t1; 199 select min(a3) from t1 where 2 = a2; 200 select max(a3) from t1 where a2 = 2 and 'SEA' > a3; 201 select max(a3) from t1 where a2 = 2 and 'SEA' < a3; 202 select min(a3) from t1 where a2 = 2 and a3 >= 'CHI'; 203 select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA'; 204 select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN'; 205 select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN'; 206 select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK'; 207 drop table t1; 208 drop table t2; 209 210 211 create table t1 (a int); 212 insert into t1 values (1); 213 select max(a) as b from t1 having b=1; 214 select a from t1 having a=1; 215 drop table t1; 216 217 218 CREATE TABLE t1 (a int primary key); 219 INSERT INTO t1 VALUES (1),(2),(3),(4); 220 221 SELECT MAX(a) FROM t1 WHERE a > 5; 222 SELECT MIN(a) FROM t1 WHERE a < 0; 223 224 DROP TABLE t1; 225 226 227 228 CREATE TABLE t1 (id int PRIMARY KEY, b char(3)); 229 INSERT INTO t1 VALUES (1,'xx'), (2,'aa'); 230 SELECT * FROM t1; 231 SELECT MAX(b) FROM t1 WHERE b < 'ppppp'; 232 SELECT MAX(b) FROM t1 WHERE b < 'pp'; 233 DROP TABLE t1; 234 235 236 CREATE TABLE t1 (id int PRIMARY KEY, b char(16)); 237 INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa'); 238 SELECT MAX(b) FROM t1; 239 DROP TABLE t1; 240 241 242 create table t1 (col1 decimal(16,12)); 243 insert into t1 values (-5.00000000001); 244 insert into t1 values (-5.00000000001); 245 select col1,sum(col1),max(col1),min(col1) from t1 group by col1; 246 delete from t1; 247 insert into t1 values (5.00000000001); 248 insert into t1 values (5.00000000001); 249 select col1,sum(col1),max(col1),min(col1) from t1 group by col1; 250 DROP TABLE t1; 251 252 253 254 create table t1 (f1 int, f2 int, f3 date, f4 datetime); 255 insert into t1 values(98,1998,"1998-01-01","1998-01-01 00:00:00"); 256 insert into t1 values('00',2000,20000101,"2000-01-01 00:00:01"); 257 insert into t1 values(02,2002,20020101,"2002-01-01 23:59:59"); 258 insert into t1 values(60,2060,20600101,"2060-01-01 11:11:11"); 259 insert into t1 values(70,1970,19700101,"1970-11-11 22:22:22"); 260 insert into t1 values(NULL,NULL,NULL,NULL); 261 -- @bvt:issue#3523 262 select min(f1),max(f1) from t1; 263 select min(f2),max(f2) from t1; 264 select min(f3),max(f3) from t1; 265 select min(f4),max(f4) from t1; 266 -- @bvt:issue 267 drop table t1; 268 269 create table t1 (grp int, a bigint unsigned, c char(10) not null); 270 insert into t1 values (1,1,"a"); 271 insert into t1 values (2,2,"b"); 272 insert into t1 values (2,3,"c"); 273 insert into t1 values (3,4,"E"); 274 insert into t1 values (3,5,"C"); 275 insert into t1 values (3,6,"D"); 276 select max(distinct a),max(distinct grp) from t1; 277 insert into t1 values (null,null,''); 278 select max(distinct a),max(distinct grp) from t1; 279 drop table t1; 280 281 CREATE TABLE t1 (a INT); 282 INSERT INTO t1 SELECT result FROM generate_series(1,100000) g; 283 SELECT MAX(a) FROM t1; 284 DELETE FROM t1 WHERE a>50000; 285 SELECT MAX(a) FROM t1; 286 DELETE FROM t1 WHERE a%2=0; 287 SELECT MAX(a) FROM t1; 288 DROP TABLE t1;