一、时间格式比较
1、使用to_date 返回比较的只是日期(即2020-12-15)
to_date(action_b->>'action_time','YYYY-MM-DD hh24:mi:ss')<to_date('2020-12-16 00:00:00','YYYY-MM-DD hh24:mi:ss')
2、使用timestamp关键字 返回结果准确
(action_b->>'action_time')::timestamp>timestamp '2020-12-15 18:02:00'
3、使用to_timestamp 返回正确
to_timestamp(action_b->>'action_time','YYYY-MM-DD hh24:mi:ss')<to_timestamp('2020-12-16 00:00:00','YYYY-MM-DD hh24:mi:ss')
二、统计
1、按照季度统计
select extract(quarter from create_time) as quarter, count(*) from action_t WHERE is_del=0 group by extract(quarter from create_time)
(其中quarter为关键字,create_time 时间格式的字段名)
pgsql 查询整理
最新推荐文章于 2024-07-10 09:43:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)