github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_aggr_max.result (about)

     1  SELECT max(null);
     2  max(null)
     3  null
     4  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));
     5  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");
     6  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");
     7  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");
     8  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");
     9  select max(a) from t1;
    10  max(a)
    11  71
    12  select max(b) from t1;
    13  max(b)
    14  71
    15  select max(c) from t1;
    16  max(c)
    17  21
    18  select max(d) from t1;
    19  max(d)
    20  43
    21  select max(e) from t1;
    22  max(e)
    23  54
    24  select max(f) from t1;
    25  max(f)
    26  53.5
    27  select max(g) from t1;
    28  max(g)
    29  431.13
    30  select max(h) from t1;
    31  max(h)
    32  124.3140000000000000000
    33  select max(i) from t1;
    34  max(i)
    35  2012-03-22
    36  select max(k) from t1;
    37  max(k)
    38  2019-03-12 10:03:12
    39  select max(l) from t1;
    40  max(l)
    41  2032-03-12 13:04:12
    42  select max(m) from t1;
    43  max(m)
    44  afbc
    45  select max(n) from t1;
    46  max(n)
    47  dcvf
    48  drop table t1;
    49  select max(99999999999999999.99999);
    50  max(99999999999999999.99999)
    51  99999999999999999.99999
    52  select max(999999999999999933193939.99999);
    53  max(999999999999999933193939.99999)
    54  999999999999999933193939.99999
    55  select max(9999999999999999999999999999999999.9999999999999);
    56  max(9999999999999999999999999999999999.9999999999999)
    57  9999999999999999999999999999999999.9999999999999
    58  create table t1(a bigint);
    59  select max(a) from t1;
    60  max(a)
    61  null
    62  insert into t1 values(null),(null),(null),(null);
    63  select max(a) from t1;
    64  max(a)
    65  null
    66  insert into t1 values(12417249128419),(124124125124151),(5124125151415),(124125152651515);
    67  select max(a) from t1;
    68  max(a)
    69  124125152651515
    70  drop table t1;
    71  create table t1 ( a int not null default 1, big bigint );
    72  insert into t1 (big) values (-1),(1234567890167),(92233720368547),(18446744073709515);
    73  select * from t1;
    74  a	big
    75  1	-1
    76  1	1234567890167
    77  1	92233720368547
    78  1	18446744073709515
    79  select min(big),max(big),max(big)-1 from t1;
    80  min(big)	max(big)	max(big)-1
    81  -1	18446744073709515	18446744073709514
    82  select min(big),max(big),max(big)-1 from t1 group by a;
    83  min(big)	max(big)	max(big)-1
    84  -1	18446744073709515	18446744073709514
    85  insert into t1 (big) values (184467440737615);
    86  select * from t1;
    87  a	big
    88  1	-1
    89  1	1234567890167
    90  1	92233720368547
    91  1	18446744073709515
    92  1	184467440737615
    93  select min(big),max(big),max(big)-1 from t1;
    94  min(big)	max(big)	max(big)-1
    95  -1	18446744073709515	18446744073709514
    96  select min(big),max(big),max(big)-1 from t1 group by a;
    97  min(big)	max(big)	max(big)-1
    98  -1	18446744073709515	18446744073709514
    99  drop table t1;
   100  create table t1 (name char(20) not null);
   101  create table t2 (name char(20) not null);
   102  insert into t1 values ("å");
   103  insert into t1 values ("ä");
   104  insert into t1 values ("ö");
   105  insert into t2 select * from t1;
   106  select * from t1 order by name;
   107  name
   108  ä
   109  å
   110  ö
   111  select concat_ws(",","*",name,"*") from t1 order by 1;
   112  concat_ws(",","*",name,"*")
   113  *,ä,*
   114  *,å,*
   115  *,ö,*
   116  select min(name),min(concat_ws(",","*",name,"*")),max(name),max(concat_ws("*",name,"*")) from t1;
   117  min(name)	min(concat_ws(",","*",name,"*"))	max(name)	max(concat_ws("*",name,"*"))
   118  å	*,å,*	ö	ö**
   119  drop table t1;
   120  drop table t2;
   121  CREATE TABLE t1 (Fld1 int(11) default NULL,Fld2 int(11) default NULL);
   122  INSERT INTO t1 VALUES (1,10),(1,20),(2,NULL),(2,NULL),(3,50);
   123  select distinct Fld1,  max( Fld2) as q from t1 group by Fld1 having q is not null;
   124  fld1    q
   125  1    20
   126  3    50
   127  select Fld1, max(Fld2) from t1 group by Fld1 having max(Fld2) is not null;
   128  Fld1	max(Fld2)
   129  1	20
   130  3	50
   131  select Fld1, max(Fld2) from t1 group by Fld1 having avg(Fld2) is not null;
   132  Fld1	max(Fld2)
   133  1	20
   134  3	50
   135  select Fld1, max(Fld2) from t1 group by Fld1 having std(Fld2) is not null;
   136  Fld1	max(Fld2)
   137  1	20
   138  3	50
   139  select Fld1, max(Fld2) from t1 group by Fld1 having variance(Fld2) is not null;
   140  Fld1	max(Fld2)
   141  1	20
   142  3	50
   143  drop table t1;
   144  create table t1 (grp int, a bigint unsigned, c char(10) not null);
   145  insert into t1 values (1,1,"a");
   146  insert into t1 values (2,2,"b");
   147  insert into t1 values (2,3,"c");
   148  insert into t1 values (3,4,"E");
   149  insert into t1 values (3,5,"C");
   150  insert into t1 values (3,6,"D");
   151  select sum(a) from t1 where a > 10;
   152  sum(a)
   153  null
   154  select count(distinct a),count(distinct grp) from t1;
   155  count(distinct a)	count(distinct grp)
   156  6	3
   157  insert into t1 values (null,null,'');
   158  select count(distinct a),count(distinct grp) from t1;
   159  count(distinct a)	count(distinct grp)
   160  6	3
   161  create table t2 (grp int, a bigint unsigned, c char(10));
   162  insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
   163  drop table t1;
   164  drop table t2;
   165  create table t1 (a1 int, a2 char(3));
   166  insert into t1 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
   167  create table t2(a1 char(3), a2 int, a3 real);
   168  select * from t1;
   169  a1	a2
   170  10	aaa
   171  10	null
   172  10	bbb
   173  20	zzz
   174  select min(a2) from t1;
   175  min(a2)
   176  aaa
   177  select max(t1.a1), max(t2.a2) from t1, t2;
   178  max(t1.a1)	max(t2.a2)
   179  null	null
   180  select max(t1.a1) from t1, t2;
   181  max(t1.a1)
   182  null
   183  select max(t2.a2), max(t1.a1) from t1, t2;
   184  max(t2.a2)	max(t1.a1)
   185  null	null
   186  insert into t2 values('AAA', 10, 0.5);
   187  insert into t2 values('BBB', 20, 1.0);
   188  select t1.a1, t1.a2, t2.a1, t2.a2 from t1,t2;
   189  a1	a2	a1	a2
   190  10	aaa	BBB	20
   191  10	aaa	AAA	10
   192  10	null	BBB	20
   193  10	null	AAA	10
   194  10	bbb	BBB	20
   195  10	bbb	AAA	10
   196  20	zzz	BBB	20
   197  20	zzz	AAA	10
   198  select max(t1.a1), max(t2.a1) from t1, t2 where t2.a2=9;
   199  max(t1.a1)	max(t2.a1)
   200  null	null
   201  select max(t2.a1), max(t1.a1) from t1, t2 where t2.a2=9;
   202  max(t2.a1)	max(t1.a1)
   203  null	null
   204  select t1.a1, t1.a2, t2.a1, t2.a2 from t1 left outer join t2 on t1.a1=10;
   205  a1	a2	a1	a2
   206  10	aaa	BBB	20
   207  10	aaa	AAA	10
   208  10	null	BBB	20
   209  10	null	AAA	10
   210  10	bbb	BBB	20
   211  10	bbb	AAA	10
   212  20	zzz	null	null
   213  select max(t1.a2) from t1 left outer join t2 on t1.a1=10;
   214  max(t1.a2)
   215  zzz
   216  select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=20;
   217  max(t2.a1)
   218  BBB
   219  select max(t2.a1) from t2 left outer join t1 on t2.a2=10 where t2.a2=10;
   220  max(t2.a1)
   221  AAA
   222  select max(t2.a1) from t1 left outer join t2 on t1.a2=t2.a1 and 1=0 where t2.a1='AAA';
   223  max(t2.a1)
   224  null
   225  select max(t1.a2),max(t2.a1) from t1 left outer join t2 on t1.a1=10;
   226  max(t1.a2)	max(t2.a1)
   227  zzz	BBB
   228  drop table t1;
   229  drop table t2;
   230  CREATE TABLE t1 (a int, b int);
   231  select count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1;
   232  count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   233  0	null	null	null	null	null	null	null
   234  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;
   235  a	count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   236  insert into t1 values (1,null);
   237  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;
   238  a	count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   239  1	0	null	null	null	null	null	null	null
   240  insert into t1 values (1,null);
   241  insert into t1 values (2,null);
   242  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;
   243  a	count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   244  1	0	null	null	null	null	null	null	null
   245  2	0	null	null	null	null	null	null	null
   246  insert into t1 values (2,1);
   247  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;
   248  a	count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   249  1	0	null	null	null	null	null	null	null
   250  2	1	1	1.0	0.0	1	1	1	1
   251  insert into t1 values (3,1);
   252  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;
   253  a	count(b)	sum(b)	avg(b)	std(b)	min(b)	max(b)	bit_and(b)	bit_or(b)
   254  1	0	null	null	null	null	null	null	null
   255  2	1	1	1.0	0.0	1	1	1	1
   256  3	1	1	1.0	0.0	1	1	1	1
   257  drop table t1;
   258  create table t1(a1 char(3) primary key,a2 smallint,a3 char(3),a4 real,a5 date);
   259  create table t2(a1 char(3) primary key,a2 char(17),a3 char(2),a4 char(3));
   260  insert into t1 values('AME',0,'SEA',0.100,date'1942-02-19');
   261  insert into t1 values('HBR',1,'SEA',0.085,date'1948-03-05');
   262  insert into t1 values('BOT',2,'SEA',0.085,date'1951-11-29');
   263  insert into t1 values('BMC',3,'SEA',0.085,date'1958-09-08');
   264  insert into t1 values('TWU',0,'LAX',0.080,date'1969-10-05');
   265  insert into t1 values('BDL',0,'DEN',0.080,date'1960-11-27');
   266  insert into t1 values('DTX',1,'NYC',0.080,date'1961-05-04');
   267  insert into t1 values('PLS',1,'WDC',0.075,date'1949-01-02');
   268  insert into t1 values('ZAJ',2,'CHI',0.075,date'1960-06-15');
   269  insert into t1 values('VVV',2,'MIN',0.075,date'1959-06-28');
   270  insert into t1 values('GTM',3,'DAL',0.070,date'1977-09-23');
   271  insert into t1 values('SSJ',null,'CHI',null,date'1974-03-19');
   272  insert into t1 values('KKK',3,'ATL',null,null);
   273  insert into t1 values('XXX',null,'MIN',null,null);
   274  insert into t1 values('WWW',1,'LED',null,null);
   275  insert into t2 values('TKF','Seattle','WA','AME');
   276  insert into t2 values('LCC','Los Angeles','CA','TWU');
   277  insert into t2 values('DEN','Denver','CO','BDL');
   278  insert into t2 values('SDC','San Diego','CA','TWU');
   279  insert into t2 values('NOL','New Orleans','LA','GTM');
   280  insert into t2 values('LAK','Los Angeles','CA','TWU');
   281  insert into t2 values('AAA','AAA','AA','AME');
   282  select * from t1;
   283  a1	a2	a3	a4	a5
   284  AME	0	SEA	0.1	1942-02-19
   285  BDL	0	DEN	0.08	1960-11-27
   286  BMC	3	SEA	0.085	1958-09-08
   287  BOT	2	SEA	0.085	1951-11-29
   288  DTX	1	NYC	0.08	1961-05-04
   289  GTM	3	DAL	0.07	1977-09-23
   290  HBR	1	SEA	0.085	1948-03-05
   291  KKK	3	ATL	null	null
   292  PLS	1	WDC	0.075	1949-01-02
   293  SSJ	null	CHI	null	1974-03-19
   294  TWU	0	LAX	0.08	1969-10-05
   295  VVV	2	MIN	0.075	1959-06-28
   296  WWW	1	LED	null	null
   297  XXX	null	MIN	null	null
   298  ZAJ	2	CHI	0.075	1960-06-15
   299  select * from t2;
   300  a1	a2	a3	a4
   301  AAA	AAA	AA	AME
   302  DEN	Denver	CO	BDL
   303  LAK	Los Angeles	CA	TWU
   304  LCC	Los Angeles	CA	TWU
   305  NOL	New Orleans	LA	GTM
   306  SDC	San Diego	CA	TWU
   307  TKF	Seattle	WA	AME
   308  select min(a1) from t1;
   309  min(a1)
   310  AME
   311  select max(a4) from t1;
   312  max(a4)
   313  0.1
   314  select min(a5), max(a5) from t1;
   315  min(a5)	max(a5)
   316  1942-02-19	1977-09-23
   317  select min(a3) from t1 where a2 = 2;
   318  min(a3)
   319  CHI
   320  select min(a1), max(a1) from t1 where a4 = 0.080;
   321  min(a1)	max(a1)
   322  BDL	TWU
   323  select min(t1.a5), max(t2.a3) from t1, t2;
   324  min(t1.a5)	max(t2.a3)
   325  1942-02-19	WA
   326  select min(t1.a3), max(t2.a2) from t1, t2 where t1.a2 = 0 and t2.a3 = 'CA';
   327  min(t1.a3)	max(t2.a2)
   328  DEN	San Diego
   329  select min(a1) from t1 where a1 > 'KKK';
   330  min(a1)
   331  PLS
   332  select min(a1) from t1 where a1 >= 'KKK';
   333  min(a1)
   334  KKK
   335  select max(a3) from t1 where a2 = 2 and a3 < 'SEA';
   336  max(a3)
   337  MIN
   338  select max(a5) from t1 where a5 < date'1970-01-01';
   339  max(a5)
   340  1969-10-05
   341  select max(a3) from t1 where a2 is null;
   342  max(a3)
   343  MIN
   344  select max(a3) from t1 where a2 = 0 and a3 between 'K' and 'Q';
   345  max(a3)
   346  LAX
   347  select min(a1), max(a1) from t1 where a1 between 'A' and 'P';
   348  min(a1)	max(a1)
   349  AME	KKK
   350  select max(a3) from t1 where a3 < 'SEA' and a2 = 2 and a3 <= 'MIN';
   351  max(a3)
   352  MIN
   353  select max(a3) from t1 where a3 = 'MIN' and a2 = 2;
   354  max(a3)
   355  MIN
   356  select max(a3) from t1 where a3 = 'DEN' and a2 = 2;
   357  max(a3)
   358  null
   359  select max(t1.a3), min(t2.a2) from t1, t2 where t1.a2 = 2 and t1.a3 < 'MIN' and t2.a3 = 'CA';
   360  max(t1.a3)	min(t2.a2)
   361  CHI	Los Angeles
   362  select max(a3) from t1 where a2 is null and a2 = 2;
   363  max(a3)
   364  null
   365  select max(a2) from t1 where a2 >= 1;
   366  max(a2)
   367  3
   368  select min(a3) from t1 where a2 = 2 and a3 < 'SEA';
   369  min(a3)
   370  CHI
   371  select min(a3) from t1 where a2 = 4;
   372  min(a3)
   373  null
   374  select min(a3) from t1 where a2 = 2 and a3 > 'SEA';
   375  min(a3)
   376  null
   377  select (min(a4)+max(a4))/2 from t1;
   378  (min(a4)+max(a4))/2
   379  0.085
   380  select min(a3) from t1 where 2 = a2;
   381  min(a3)
   382  CHI
   383  select max(a3) from t1 where a2 = 2 and 'SEA' > a3;
   384  max(a3)
   385  MIN
   386  select max(a3) from t1 where a2 = 2 and 'SEA' < a3;
   387  max(a3)
   388  null
   389  select min(a3) from t1 where a2 = 2 and a3 >= 'CHI';
   390  min(a3)
   391  CHI
   392  select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 < 'SEA';
   393  min(a3)
   394  CHI
   395  select min(a3) from t1 where a2 = 2 and a3 >= 'CHI' and a3 = 'MIN';
   396  min(a3)
   397  MIN
   398  select min(a3) from t1 where a2 = 2 and a3 >= 'SEA' and a3 = 'MIN';
   399  min(a3)
   400  null
   401  select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
   402  min(t1.a1)	min(t2.a4)
   403  AME	AME
   404  drop table t1;
   405  drop table t2;
   406  create table t1 (a int);
   407  insert into t1 values (1);
   408  select max(a) as b from t1 having b=1;
   409  b
   410  1
   411  select a from t1 having a=1;
   412  SQL syntax error: column "t1.a" must appear in the GROUP BY clause or be used in an aggregate function
   413  drop table t1;
   414  CREATE TABLE t1 (a int primary key);
   415  INSERT INTO t1 VALUES (1),(2),(3),(4);
   416  SELECT MAX(a) FROM t1 WHERE a > 5;
   417  MAX(a)
   418  null
   419  SELECT MIN(a) FROM t1 WHERE a < 0;
   420  MIN(a)
   421  null
   422  DROP TABLE t1;
   423  CREATE TABLE t1 (id int PRIMARY KEY, b char(3));
   424  INSERT INTO t1 VALUES (1,'xx'), (2,'aa');
   425  SELECT * FROM t1;
   426  id	b
   427  1	xx
   428  2	aa
   429  SELECT MAX(b) FROM t1 WHERE b < 'ppppp';
   430  MAX(b)
   431  aa
   432  SELECT MAX(b) FROM t1 WHERE b < 'pp';
   433  MAX(b)
   434  aa
   435  DROP TABLE t1;
   436  CREATE TABLE t1 (id int PRIMARY KEY, b char(16));
   437  INSERT INTO t1 VALUES (1, 'xxxxbbbb'), (2, 'xxxxaaaa');
   438  SELECT MAX(b) FROM t1;
   439  MAX(b)
   440  xxxxbbbb
   441  DROP TABLE t1;
   442  create table t1 (col1 decimal(16,12));
   443  insert into t1 values (-5.00000000001);
   444  insert into t1 values (-5.00000000001);
   445  select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
   446  col1	sum(col1)	max(col1)	min(col1)
   447  -5.000000000010	-10.000000000020	-5.000000000010	-5.000000000010
   448  delete from t1;
   449  insert into t1 values (5.00000000001);
   450  insert into t1 values (5.00000000001);
   451  select col1,sum(col1),max(col1),min(col1) from t1 group by col1;
   452  col1	sum(col1)	max(col1)	min(col1)
   453  5.000000000010	10.000000000020	5.000000000010	5.000000000010
   454  DROP TABLE t1;
   455  create table t1 (f1 int, f2 int, f3 date, f4 datetime);
   456  insert into t1 values(98,1998,"1998-01-01","1998-01-01 00:00:00");
   457  insert into t1 values('00',2000,20000101,"2000-01-01 00:00:01");
   458  invalid argument operator cast, bad value [BIGINT DATE]
   459  insert into t1 values(02,2002,20020101,"2002-01-01 23:59:59");
   460  invalid argument operator cast, bad value [BIGINT DATE]
   461  insert into t1 values(60,2060,20600101,"2060-01-01 11:11:11");
   462  invalid argument operator cast, bad value [BIGINT DATE]
   463  insert into t1 values(70,1970,19700101,"1970-11-11 22:22:22");
   464  invalid argument operator cast, bad value [BIGINT DATE]
   465  insert into t1 values(NULL,NULL,NULL,NULL);
   466  select min(f1),max(f1) from t1;
   467  min(f1)	max(f1)
   468  0	98
   469  select min(f2),max(f2) from t1;
   470  min(f2)	max(f2)
   471  0	1998
   472  select min(f3),max(f3) from t1;
   473  min(f3)	max(f3)
   474  0001-01-01	1998-01-01
   475  select min(f4),max(f4) from t1;
   476  min(f4)	max(f4)
   477  0001-01-01 00:00:00	1998-01-01 00:00:00
   478  drop table t1;
   479  create table t1 (grp int, a bigint unsigned, c char(10) not null);
   480  insert into t1 values (1,1,"a");
   481  insert into t1 values (2,2,"b");
   482  insert into t1 values (2,3,"c");
   483  insert into t1 values (3,4,"E");
   484  insert into t1 values (3,5,"C");
   485  insert into t1 values (3,6,"D");
   486  select max(distinct a),max(distinct grp) from t1;
   487  max(distinct a)	    max(distinct grp)
   488  6	3
   489  insert into t1 values (null,null,'');
   490  select max(distinct a),max(distinct grp) from t1;
   491  max(distinct a)	    max(distinct grp)
   492  6	3
   493  drop table t1;
   494  
   495  CREATE TABLE t1 (a INT);
   496  INSERT INTO t1 SELECT result FROM generate_series(1,100000) g;
   497  SELECT MAX(a) FROM t1;
   498  max(a)
   499  100000
   500  DELETE FROM t1 WHERE a>50000;
   501  SELECT MAX(a) FROM t1;
   502  max(a)
   503  50000
   504  DELETE FROM t1 WHERE a%2=0;
   505  SELECT MAX(a) FROM t1;
   506  max(a)
   507  49999
   508  DROP TABLE t1;