user, timeon, timeoff, hours
Monday -
1510, 2021-10-25 05:00:00, 2021-10-25 09:00:00 -
1510, 2021-10-25 14:00:00, 2021-10-25 17:00:00 -
The total should be 4 + 3 = 7
Tuesday -
1510, 2021-10-25 05:00:00, 2021-10-25 09:00:00 -
1510, 2021-10-25 14:00:00, 2021-10-25 17:00:00 -
The total should be 4 + 3 = 7, then total at the end of the week
I have a user, timeon, timeoff for each day as they might be on and off more than once. I have a total at the bottom datediff(minute, timeon, timeoff)
. I'm using Firebird 3.
I have a virtual table
with M as
(
select user, timeon, timeoff, hours
from (select userid, timeon, timeoff,
datediff(minute,timeon, timeoff)/60.00 as hours
from sessions s
where extract(weekday from timeon)=1
and userID=1
and cast(logon as date)='2021-10-28')
)
select * from M
union all
select '','','',sum(hours) from M
Now, I need to repeat the above but for a Tuesday, then Wednesday and so on. I can't start with another v table nor a union. What am I doing wrong?