想要查询一个时间字段中大于0点小于两点之间的时间和大于两点之后的时间
select a.sqr '申请人',h.lastname,a.sqrq '申请日期',b.jbrq as '开始日期',b.jsrq as '结束日期',
b.sjkssj as '实际开始时间',b.sjjssj as '实际结束时间',b.sjsc as '加班时长',
case b.sjjssj
when b.sjjssj >='00:00:00' and b.sjjssj <'02:00:00' then 50
when b.sjjssj >'02:00:00' then 80
end '加班补贴'
from formtable_main_52 a
left join formtable_main_52_dt1 b on a.id = b.mainid
left join hrmresource h on h.id=a.sqr
left join workflow_requestbase w on a.requestid=w.requestid
where b.jsrq>b.jbrq and w.currentnodetype=3
但是查询出来的结果:
287 代绪军 2022-03-24 2022-03-15 2022-03-16 17:30 00:06 6 80
287 代绪军 2022-03-24 2022-03-18 2022-03-19 17:31 00:30 6.5 80
284 孙宏伟 2022-03-24 2022-03-18 2022-03-19 17:07 00:38 7 80
284 孙宏伟 2022-03-24 2022-03-15 2022-03-16 17:30 00:06 6 80
285 李彩玲 2022-03-24 2022-03-15 2022-03-16 17:30 00:06 6 80
285 李彩玲 2022-03-24 2022-03-18 2022-03-19 17:38 00:40 6.5 80
260 卞友鹏 2022-04-02 2022-04-01 2022-04-02 17:00 02:30 9
41 李小文 2022-04-02 2022-04-01 2022-04-02 17:20 03:00 9
315 张云芳 2022-04-02 2022-04-01 2022-04-02 17:00 03:00 9.5
303 余安银 2022-04-02 2022-04-01 2022-04-02 17:00 03:00 9.5
时间比较不可以使用> ,<这种比较方式吗,我试了在where条件后直接写b.sjjssj>'02:00' 查出来的结果是正确的呢,
但是在case when上面 then的结果就不对 ,是什么情况呢 郁闷
方法一:把时间转换成时间戳 when b.sjjssj >=unix_timestamp('2022-06-06 00:00:00') and b.sjjssj <unix_timestamp('2022-06-06 02:00:00') then 50
方法二: when b.sjjssj BETWEEN '00:00:00' AND b.sjjssj < '02:00:00' then 50
你需要提供:实际结束时间的字段类型。
简单处理:把这个字段转字符串后比较。