输入表:
store | employee | date | timein | timeout |
1 | A | 1-jan-12 | 10:00 | 17:00 |
1 | A | 1-jan-12 | 20:00 | 22:00 |
2 | B | 1-jan-12 | 10:00 | - |
2 | B | 1-jan-12 | 17:00 | 20:00 |
2 | B | 2-jan-12 | 10:00 | 17:00 |
3 | C | 1-jan-12 | 10:00 | 12:00 |
3 | C | 1-jan-12 | 13:00 | 15:00 |
3 | C | 1-jan-12 | 20:00 | 23:00 |
期望的输出:
store | employee | date | timein | timeout | hours | working_days |
1 | A | 1-jan-12 | 10:00 | 17:00 | 7 | |
1 | A | 1-jan-12 | 20:00 | 22:00 | 2 | 1 |
2 | B | 1-jan-12 | 10:00 | - | 0 | |
2 | B | 1-jan-12 | 17:00 | 20:00 | 5 | 0 |
2 | B | 2-jan-12 | 10:00 | 17:00 | 7 | 1 |
3 | C | 1-jan-12 | 10:00 | 12:00 | 2 | |
3 | C | 1-jan-12 | 13:00 | 15:00 | 2 | |
3 | C | 1-jan-12 | 20:00 | 23:00 | 3 | 1 |
我的查询是:
select
store,
employee,
date,
timein,
timeout,
cast(trim(trailing ':' from cast(timeout) as number)-trim(trailing ':' from cast(timein) as number) as number) as hours,
case
when timeout is null then 0 and
end
from
tableattend
where date between '1-jan-12' and '2-jan-12' and store between 'A' and 'C'
working_days字段将以这种方式显示,但无法获得创建上述结果的确切函数。请指导我。