doris脚本

partition by

distributed by

date_trunc

将datetime按照指定的时间单位截断,即保留指定单位及更高层级的时间信息,将低层级的时间信息清零。


select date_trunc('2010-12-02 19:28:30', 'hour'),返回'2010-12-02 19:00:00'

select date_trunc('2010-12-02 19:28:30', 'day'),返回'2010-12-02 00:00:00'

 

date_add:date_add(<date_or_time_expr>, interval <expr> <time_unit>)

向指定的日期或时间值添加指定的时间间隔

select date_add('2023-01-31', interval 1 month),返回'2023-02-28'

select date_add('2019-01-01', interval  -3 DAY),返回'2018-12-29'

其实也可以不用date_add函数,datetime类型可以直接加减,并且可以多次加减。

date_add('2023-01-31', interval 1 month)等价于cast('2023-01-31' as datetime) + interval 1 month

cast('2023-01-31' as datetime) + interval 1 month + interval 1 day - interval 8 hour,会得到一个有效的datetime。

left semi join

select * from A left semi join B on A.user_id=B.id

是select * from A where A.user_id in (select id from B)的优化写法,只会返回A表的字段,B的字段不会返回。

left anti join

select * from A left anti join B on A.user_id=B.id

是select * from A where A.user_id not in (select id from B)的优化写法,只会返回A表的字段,B的字段不会返回。

posted on 2026-04-30 14:31  koushr  阅读(24)  评论(0)    收藏  举报

导航