oracle查询一段时间的语句

2020-03-25

一个月的数据,要统计最近几天或者晚上或者周末的量。

1、最近5天
select count(1) from t1 where create_time between trunc(sysdate-5) and trunc(sysdate);
2、晚上21点-9点
SELECT COUNT(*),sum(msg_count) FROM JS_CHAT_RECORD_${ym} a where a.user_id like 'AI-%' and a.create_time between TO_DATE('${start_date} 00:00:00', 'YYYYMMDD HH24:MI:SS') and TO_DATE('${end_date} 00:00:00', 'YYYYMMDD HH24:MI:SS') and to_char(a.create_time, 'HH24') between 09 and 22;
select count(1) from visitor_info where to_char(create_time, 'HH24') between 9 and 21;
3、周末
a) trim(string); --去除字符串首尾的空格
b) rtrim(string); --去除字符串右侧空格
c) ltrim(string); --去除字符串左侧空格
trim函数的用法不仅仅局限于去除字符串的空格,select trim(' dylan ') "test_trim" from dual;

where to_char( to_date('2020/10/21','YYYY/MM/DD'),'d') in ('1','7')
where trim(to_char( to_date('2020/10/21','YYYY/MM/DD'),'day')) in ('saturday','sunday')
SELECT COUNT(*) FROM t3_${ym} a where to_char(a.create_time, 'd')=1 or to_char(a.create_time, 'd')=7;

分类:数据库 | 标签: |

相关日志

评论被关闭!