如题,这个SQL条件语句该怎么写?
两个单独的会写,组合在一起怎么写?
a.recoding_date是这个时间格式:2020/12/14 10:46:07
过去7天:and a.recoding_date between convert(varchar(10),dateadd(day,-7,getdate()),23)and convert(varchar(10),getdate(),23)
8-17点:and a.recoding_date between '08:00:00' and convert(varchar(20),getdate(),108)
具体我就不写了,结构加一加就行了
一个有趣的 SQL 查询(查询7天连续登陆) - mjorcen - 博客园 一个有趣的 SQL 查询一个朋友有这样一个SQL查询需求:有一个登录表(tmp_test),包含用户ID(uid)和登录时间(login_time)。表结构如下:******************* https://www.cnblogs.com/mjorcen/p/4020796.html
↑是查询过去7天的
SQL��ô��ѯ8:30��17:00֮������ݣ�_�ٶ�֪�� https://zhidao.baidu.com/question/490781138585834252.html
↑是查询8:30至17:00之间的
加一加就行了
where条件:substr(to_char(recoding_date,'yyyymmdd hh24:mi:ss') ,12,13)between '08' and '17' and recoding_date between sysdate-7 and sysdate;
或者直接
trunc(recoding_date,'DD') between trunc(recoding_date,'DD')+8/24 and trunc(recoding_date,'DD')+17/24 and recoding_date between sysdate-7 and sysdate;