1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-26 11:48:52 +03:00
2022-12-09 02:24:40 +00:00

255 lines
9.3 KiB
Plaintext

USE ssb1;
drop table if exists datetest;
create table if not exists datetest (rowid int, c1 varchar(20), c2 bigint) engine=columnstore;
insert into datetest values (1, "1990-10-20", 19901121), (2, "1997-01-01 10:00:05", 19970201000000), (3, "0705", 0805), (4, "20120230", 20120230),(5, "20110229", 20110229),(6, "9905", 9905),(7, "20011010888888", 20031010888888),(8, "20011011124455", 20011010122233);
select 'q1', rowid, c1, c2, cast(c1 as date), cast(c2 as date) from datetest where c2 <> 0805 order by rowid;
q1 rowid c1 c2 cast(c1 as date) cast(c2 as date)
q1 1 1990-10-20 19901121 1990-10-20 1990-11-21
q1 2 1997-01-01 10:00:05 19970201000000 1997-01-01 1997-02-01
q1 4 20120230 20120230 NULL NULL
q1 5 20110229 20110229 NULL NULL
q1 6 9905 9905 NULL NULL
q1 7 20011010888888 20031010888888 NULL NULL
q1 8 20011011124455 20011010122233 2001-10-11 2001-10-10
select 'q1b', rowid, c1, c2, cast(c1 as date), substr(cast(c2 as date), 6, 5) from datetest where c2 = 0805 order by rowid;
q1b rowid c1 c2 cast(c1 as date) substr(cast(c2 as date), 6, 5)
q1b 3 0705 805 NULL 08-05
select 'q2', rowid, c1, c2, cast(c1 as date), cast(c2 as datetime) from datetest where c2 <> 0805 order by rowid;
q2 rowid c1 c2 cast(c1 as date) cast(c2 as datetime)
q2 1 1990-10-20 19901121 1990-10-20 1990-11-21 00:00:00
q2 2 1997-01-01 10:00:05 19970201000000 1997-01-01 1997-02-01 00:00:00
q2 4 20120230 20120230 NULL NULL
q2 5 20110229 20110229 NULL NULL
q2 6 9905 9905 NULL NULL
q2 7 20011010888888 20031010888888 NULL NULL
q2 8 20011011124455 20011010122233 2001-10-11 2001-10-10 12:22:33
select 'q2b', rowid, c1, c2, cast(c1 as date), substr(cast(c2 as datetime), 6, 14) from datetest where c2 = 0805 order by rowid;
q2b rowid c1 c2 cast(c1 as date) substr(cast(c2 as datetime), 6, 14)
q2b 3 0705 805 NULL 08-05 00:00:00
select 'q3', rowid, c1, c2, quarter(c1), quarter(c2) from datetest order by rowid;
q3 rowid c1 c2 quarter(c1) quarter(c2)
q3 1 1990-10-20 19901121 4 4
q3 2 1997-01-01 10:00:05 19970201000000 1 1
q3 3 0705 805 NULL 3
q3 4 20120230 20120230 NULL NULL
q3 5 20110229 20110229 NULL NULL
q3 6 9905 9905 NULL NULL
q3 7 20011010888888 20031010888888 NULL NULL
q3 8 20011011124455 20011010122233 4 4
select 'q4', rowid, c1, c2 from datetest where quarter(c1) = quarter(c2) order by rowid;
q4 rowid c1 c2
q4 1 1990-10-20 19901121
q4 2 1997-01-01 10:00:05 19970201000000
q4 8 20011011124455 20011010122233
select 'q5', rowid, c1, c2, timediff(c1,c2) from datetest order by rowid;
q5 rowid c1 c2 timediff(c1,c2)
q5 1 1990-10-20 19901121 NULL
q5 2 1997-01-01 10:00:05 19970201000000 -733:59:55.000000
q5 3 0705 805 -00:01:00.000000
q5 4 20120230 20120230 NULL
q5 5 20110229 20110229 NULL
q5 6 9905 9905 NULL
q5 7 20011010888888 20031010888888 NULL
q5 8 20011011124455 20011010122233 24:22:22.000000
select 'q6', rowid, c1, c2, date_format(c1, '%W %M %Y'), date_format(c2, '%H:%i:%s') from datetest order by rowid;
q6 rowid c1 c2 date_format(c1, '%W %M %Y') date_format(c2, '%H:%i:%s')
q6 1 1990-10-20 19901121 Saturday October 1990 00:00:00
q6 2 1997-01-01 10:00:05 19970201000000 Wednesday January 1997 00:00:00
q6 3 0705 805 NULL 00:00:00
q6 4 20120230 20120230 NULL NULL
q6 5 20110229 20110229 NULL NULL
q6 6 9905 9905 NULL NULL
q6 7 20011010888888 20031010888888 NULL NULL
q6 8 20011011124455 20011010122233 Thursday October 2001 12:22:33
select 'q7', rowid, c1, c2, c1 + interval 2 day, c2 + interval 12 hour from datetest where c2 <> 0805 order by rowid;
q7 rowid c1 c2 c1 + interval 2 day c2 + interval 12 hour
q7 1 1990-10-20 19901121 1990-10-22 00:00:00.0000 1990-11-21 12:00:00
q7 2 1997-01-01 10:00:05 19970201000000 1997-01-03 10:00:05.0000 1997-02-01 12:00:00
q7 4 20120230 20120230 NULL NULL
q7 5 20110229 20110229 NULL NULL
q7 6 9905 9905 NULL NULL
q7 7 20011010888888 20031010888888 NULL NULL
q7 8 20011011124455 20011010122233 2001-10-13 12:44:55.0000 2001-10-11 00:22:33
select 'q7b', rowid, c1, c2, c1 + interval 2 day, substr(c2 + interval 12 hour, 6, 14) from datetest where c2 = 0805 order by rowid;
q7b rowid c1 c2 c1 + interval 2 day substr(c2 + interval 12 hour, 6, 14)
q7b 3 0705 805 NULL 08-05 12:00:00
select 'q8', rowid, c1, c2, minute(c1), minute(c2) from datetest order by rowid;
q8 rowid c1 c2 minute(c1) minute(c2)
q8 1 1990-10-20 19901121 0 0
q8 2 1997-01-01 10:00:05 19970201000000 0 0
q8 3 0705 805 NULL 0
q8 4 20120230 20120230 NULL NULL
q8 5 20110229 20110229 NULL NULL
q8 6 9905 9905 NULL NULL
q8 7 20011010888888 20031010888888 NULL NULL
q8 8 20011011124455 20011010122233 44 22
select 'q9', rowid, c1, c2, day(c1), day(c2) from datetest order by 1,2;
q9 rowid c1 c2 day(c1) day(c2)
q9 1 1990-10-20 19901121 20 21
q9 2 1997-01-01 10:00:05 19970201000000 1 1
q9 3 0705 805 NULL 5
q9 4 20120230 20120230 NULL NULL
q9 5 20110229 20110229 NULL NULL
q9 6 9905 9905 NULL NULL
q9 7 20011010888888 20031010888888 NULL NULL
q9 8 20011011124455 20011010122233 11 10
select 'q10', rowid, c1, c2, hour(c1), hour(c2) from datetest order by 1,2;
q10 rowid c1 c2 hour(c1) hour(c2)
q10 1 1990-10-20 19901121 0 0
q10 2 1997-01-01 10:00:05 19970201000000 10 0
q10 3 0705 805 NULL 0
q10 4 20120230 20120230 NULL NULL
q10 5 20110229 20110229 NULL NULL
q10 6 9905 9905 NULL NULL
q10 7 20011010888888 20031010888888 NULL NULL
q10 8 20011011124455 20011010122233 12 12
select 'q11', rowid, c1, c2, dayofweek(c1), dayofweek(c2) from datetest where c2 <> 0805 order by 1,2;
q11 rowid c1 c2 dayofweek(c1) dayofweek(c2)
q11 1 1990-10-20 19901121 7 4
q11 2 1997-01-01 10:00:05 19970201000000 4 7
q11 4 20120230 20120230 NULL NULL
q11 5 20110229 20110229 NULL NULL
q11 6 9905 9905 NULL NULL
q11 7 20011010888888 20031010888888 NULL NULL
q11 8 20011011124455 20011010122233 5 4
select 'q12', rowid, c1, c2, dayofyear(c1), dayofyear(c2) from datetest where c2 <> 0805 order by 1,2;
q12 rowid c1 c2 dayofyear(c1) dayofyear(c2)
q12 1 1990-10-20 19901121 293 325
q12 2 1997-01-01 10:00:05 19970201000000 1 32
q12 4 20120230 20120230 NULL NULL
q12 5 20110229 20110229 NULL NULL
q12 6 9905 9905 NULL NULL
q12 7 20011010888888 20031010888888 NULL NULL
q12 8 20011011124455 20011010122233 284 283
select 'q13', rowid, c1, c2, week(c1), week(c2) from datetest where c2 <> 0805 order by 1,2;
q13 rowid c1 c2 week(c1) week(c2)
q13 1 1990-10-20 19901121 41 46
q13 2 1997-01-01 10:00:05 19970201000000 0 4
q13 4 20120230 20120230 NULL NULL
q13 5 20110229 20110229 NULL NULL
q13 6 9905 9905 NULL NULL
q13 7 20011010888888 20031010888888 NULL NULL
q13 8 20011011124455 20011010122233 40 40
select 'q14', rowid, second(c1), second(c2) from datetest order by 1,2;
q14 rowid second(c1) second(c2)
q14 1 0 0
q14 2 5 0
q14 3 NULL 0
q14 4 NULL NULL
q14 5 NULL NULL
q14 6 NULL NULL
q14 7 NULL NULL
q14 8 55 33
select 'q15', rowid, c1, c2, year(c1), year(c2) from datetest where c2 <> 0805 order by 1,2;
q15 rowid c1 c2 year(c1) year(c2)
q15 1 1990-10-20 19901121 1990 1990
q15 2 1997-01-01 10:00:05 19970201000000 1997 1997
q15 4 20120230 20120230 NULL NULL
q15 5 20110229 20110229 NULL NULL
q15 6 9905 9905 NULL NULL
q15 7 20011010888888 20031010888888 NULL NULL
q15 8 20011011124455 20011010122233 2001 2001
select 'q16', rowid, c1, c2, month(c1), month(c2) from datetest order by 1,2;
q16 rowid c1 c2 month(c1) month(c2)
q16 1 1990-10-20 19901121 10 11
q16 2 1997-01-01 10:00:05 19970201000000 1 2
q16 3 0705 805 NULL 8
q16 4 20120230 20120230 NULL NULL
q16 5 20110229 20110229 NULL NULL
q16 6 9905 9905 NULL NULL
q16 7 20011010888888 20031010888888 NULL NULL
q16 8 20011011124455 20011010122233 10 10
select 'q17', rowid, c1, c2, time(c1), time(c2) from datetest order by 1,2;
q17 rowid c1 c2 time(c1) time(c2)
q17 1 1990-10-20 19901121 NULL 00:00:00
q17 2 1997-01-01 10:00:05 19970201000000 10:00:05.000000 00:00:00
q17 3 0705 805 00:07:05.000000 00:08:05
q17 4 20120230 20120230 838:59:59.999999 00:00:00
q17 5 20110229 20110229 838:59:59.999999 00:00:00
q17 6 9905 9905 NULL NULL
q17 7 20011010888888 20031010888888 NULL NULL
q17 8 20011011124455 20011010122233 12:44:55.000000 12:22:33
select 'q18', year(lo_orderdate), month(lo_orderdate), count(*) from ssb1.lineorder group by 1, 2, 3 order by 1, 2, 3;
q18 year(lo_orderdate) month(lo_orderdate) count(*)
q18 1992 1 77440
q18 1992 2 71974
q18 1992 3 77322
q18 1992 4 74258
q18 1992 5 76361
q18 1992 6 74587
q18 1992 7 77167
q18 1992 8 76217
q18 1992 9 74315
q18 1992 10 76928
q18 1992 11 73794
q18 1992 12 77631
q18 1993 1 77007
q18 1993 2 69730
q18 1993 3 77089
q18 1993 4 74824
q18 1993 5 76108
q18 1993 6 75017
q18 1993 7 77724
q18 1993 8 76628
q18 1993 9 75339
q18 1993 10 76988
q18 1993 11 75023
q18 1993 12 76761
q18 1994 1 78537
q18 1994 2 69066
q18 1994 3 78095
q18 1994 4 74494
q18 1994 5 77182
q18 1994 6 75261
q18 1994 7 76596
q18 1994 8 77690
q18 1994 9 74736
q18 1994 10 75569
q18 1994 11 75507
q18 1994 12 77786
q18 1995 1 77914
q18 1995 2 71096
q18 1995 3 77112
q18 1995 4 75695
q18 1995 5 76770
q18 1995 6 75530
q18 1995 7 77978
q18 1995 8 77977
q18 1995 9 74836
q18 1995 10 77848
q18 1995 11 74701
q18 1995 12 76470
q18 1996 1 76859
q18 1996 2 73197
q18 1996 3 76283
q18 1996 4 74941
q18 1996 5 76445
q18 1996 6 75728
q18 1996 7 76868
q18 1996 8 79102
q18 1996 9 75401
q18 1996 10 77467
q18 1996 11 75472
q18 1996 12 77728
q18 1997 1 76351
q18 1997 2 70499
q18 1997 3 76106
q18 1997 4 75915
q18 1997 5 78040
q18 1997 6 75284
q18 1997 7 77549
q18 1997 8 77286
q18 1997 9 74530
q18 1997 10 77324
q18 1997 11 73744
q18 1997 12 77391
q18 1998 1 77437
q18 1998 2 70453
q18 1998 3 77588
q18 1998 4 74713
q18 1998 5 77725
q18 1998 6 74584
q18 1998 7 77744
q18 1998 8 4783
drop table if exists datetest;