github.com/matrixorigin/matrixone@v0.7.0/test/distributed/cases/subquery/from-subquery.sql (about)

     1  
     2  -- @suite
     3  -- @setup
     4  drop table if exists t1;
     5  create table t1 (id int,ti tinyint unsigned,si smallint,bi bigint unsigned,fl float,dl double,de decimal,ch char(20),vch varchar(20),dd date,dt datetime);
     6  insert into t1 values(1,1,4,3,1113.32,111332,1113.32,'hello','subquery','2022-04-28','2022-04-28 22:40:11');
     7  insert into t1 values(2,2,5,2,2252.05,225205,2252.05,'bye','sub query','2022-04-28','2022-04-28 22:40:11');
     8  insert into t1 values(3,6,6,3,3663.21,366321,3663.21,'hi','subquery','2022-04-28','2022-04-28 22:40:11');
     9  insert into t1 values(4,7,1,5,4715.22,471522,4715.22,'good morning','my subquery','2022-04-28','2022-04-28 22:40:11');
    10  insert into t1 values(5,1,2,6,51.26,5126,51.26,'byebye',' is subquery?','2022-04-28','2022-04-28 22:40:11');
    11  insert into t1 values(6,3,2,1,632.1,6321,632.11,'good night','maybe subquery','2022-04-28','2022-04-28 22:40:11');
    12  insert into t1 values(7,4,4,3,7443.11,744311,7443.11,'yes','subquery','2022-04-28','2022-04-28 22:40:11');
    13  insert into t1 values(8,7,5,8,8758.00,875800,8758.11,'nice to meet','just subquery','2022-04-28','2022-04-28 22:40:11');
    14  insert into t1 values(9,8,4,9,9849.312,9849312,9849.312,'see you','subquery','2022-04-28','2022-04-28 22:40:11');
    15  
    16  drop table if exists t2;
    17  create table t2 (id int,ti tinyint unsigned,si smallint,bi bigint unsigned,fl float,dl double,de decimal,ch char(20),vch varchar(20),dd date,dt datetime);
    18  insert into t2 values(1,1,4,3,1113.32,111332,1113.32,'hello','subquery','2022-04-28','2022-04-28 22:40:11');
    19  insert into t2 values(2,2,5,2,2252.05,225205,2252.05,'bye','sub query','2022-04-28','2022-04-28 22:40:11');
    20  insert into t2 values(3,6,6,3,3663.21,366321,3663.21,'hi','subquery','2022-04-28','2022-04-28 22:40:11');
    21  insert into t2 values(4,7,1,5,4715.22,471522,4715.22,'good morning','my subquery','2022-04-28','2022-04-28 22:40:11');
    22  insert into t2 values(5,1,2,6,51.26,5126,51.26,'byebye',' is subquery?','2022-04-28','2022-04-28 22:40:11');
    23  insert into t2 values(6,3,2,1,632.1,6321,632.11,'good night','maybe subquery','2022-04-28','2022-04-28 22:40:11');
    24  insert into t2 values(7,4,4,3,7443.11,744311,7443.11,'yes','subquery','2022-04-28','2022-04-28 22:40:11');
    25  insert into t2 values(8,7,5,8,8758.00,875800,8758.11,'nice to meet','just subquery','2022-04-28','2022-04-28 22:40:11');
    26  insert into t2 values(9,8,4,9,9849.312,9849312,9849.312,'see you','subquery','2022-04-28','2022-04-28 22:40:11');
    27  
    28  -- @case
    29  -- @desc:test for from subquery
    30  -- @label:bvt
    31  select * from (select * from t1) sub where id > 4;
    32  select ti as t,fl as f from (select * from t1) sub where dl <> 4;
    33  select * from (select ti as t,fl as f from t1 where dl <> 4) sub;
    34  
    35  select id,min(ti) from (select * from t1) sub group by id;
    36  select * from (select id,min(ti) from (select * from t1) t1 group by id) sub;
    37  
    38  --待确认
    39  --select id,min(ti) from (select * from t1) sub order by id desc;
    40  --select * from (select id,min(ti) from t1 sub order by id desc) sub;
    41  
    42  select id,min(ti) from (select * from t1) sub group by id order by id desc;
    43  select id,sum(ti) from (select * from t1) sub group by id;
    44  
    45  select distinct(ti) from (select * from t1) sub;
    46  select distinct(ti) from (select * from t1) sub where id <6;
    47  
    48  -- mysql 不同,待确认
    49  -- select distinct(ti),de from (select * from t1) sub where id < 6 order by ti asc;
    50  
    51  select count(*) from (select * from t1) sub where id > 4 ;
    52  select * from (select * from t1) sub where id > 1 limit 3;
    53  select max(ti),min(si),avg(fl) from (select * from t1) sub where id < 4 || id > 5;
    54  select max(ti)+10,min(si)-1,avg(fl) from (select * from t1) sub where id < 4 || id > 5;
    55  
    56  select substr from (select * from t1) sub where id < 4 || id > 5;
    57  
    58  select ti,-si from (select * from t1) sub order by -si desc;
    59  
    60  select * from (select * from t1) sub where (ti=2 or si=3) and  (ch = 'bye' or vch = 'subquery');
    61  
    62  select * from (select * from (select * from (select id,ti,si,de from (select * from t1 ) sub3 where fl <> 4.5 ) sub2 where ti > 1) sub1 where id >2 ) sub where id > 4;
    63  
    64  select * from (select * from t1 where id > 100) sub ;
    65  
    66  -- @suite
    67  -- @setup
    68  drop table if exists t1;
    69  drop table if exists t2;
    70  drop table if exists t3;
    71  create table t1 (libname1 varchar(21) not null primary key, city varchar(20));
    72  create table t2 (isbn2 varchar(21) not null primary key, author varchar(20), title varchar(60));
    73  create table t3 (isbn3 varchar(21) not null, libname3 varchar(21) not null, quantity int);
    74  insert into t2 values ('001','Daffy','Aducklife');
    75  insert into t2 values ('002','Bugs','Arabbitlife');
    76  insert into t2 values ('003','Cowboy','Lifeontherange');
    77  insert into t2 values ('000','Anonymous','Wannabuythisbook?');
    78  insert into t2 values ('004','BestSeller','OneHeckuvabook');
    79  insert into t2 values ('005','EveryoneBuys','Thisverybook');
    80  insert into t2 values ('006','SanFran','Itisasanfranlifestyle');
    81  insert into t2 values ('007','BerkAuthor','Cool.Berkley.the.book');
    82  insert into t3 values('000','NewYorkPublicLibra',1);
    83  insert into t3 values('001','NewYorkPublicLibra',2);
    84  insert into t3 values('002','NewYorkPublicLibra',3);
    85  insert into t3 values('003','NewYorkPublicLibra',4);
    86  insert into t3 values('004','NewYorkPublicLibra',5);
    87  insert into t3 values('005','NewYorkPublicLibra',6);
    88  insert into t3 values('006','SanFransiscoPublic',5);
    89  insert into t3 values('007','BerkeleyPublic1',3);
    90  insert into t3 values('007','BerkeleyPublic2',3);
    91  insert into t3 values('001','NYC Lib',8);
    92  insert into t1 values ('NewYorkPublicLibra','NewYork');
    93  insert into t1 values ('SanFransiscoPublic','SanFran');
    94  insert into t1 values ('BerkeleyPublic1','Berkeley');
    95  insert into t1 values ('BerkeleyPublic2','Berkeley');
    96  insert into t1 values ('NYCLib','NewYork');
    97  -- @case
    98  -- @desc:test for from subquery with join
    99  -- @label:bvt
   100  select * from (select city,libname1,count(libname1) as a from t3 join t1 on libname1=libname3 join t2 on isbn3=isbn2 group by city,libname1) sub ;
   101  drop table if exists t1;
   102  create table t1(a int);
   103  insert into t1 values(1);
   104  select * from (select * from t1) tt, (select * from t1);
   105  select * from (select * from t1), (select * from t1);