O código que estou usando está aqui
CREATE TABLE timecard (
id INTEGER PRIMARY KEY autoincrement,
clock_in REAL not null,
clock_out REAL,
lunch integer,
pay_type TEXT
);
INSERT INTO timecard VALUES(1,julianday("2021-02-15 08:00"),julianday("2021-02-15 16:00"),0,"HOLIDAY");
INSERT INTO timecard VALUES(2,julianday("2021-02-16 07:23"),julianday("2021-02-16 16:49"),1,"WORK");
INSERT INTO timecard VALUES(3,julianday("2021-02-17 07:16"),julianday("2021-02-17 16:05"),1,"WORK");
INSERT INTO timecard VALUES(4,julianday("2021-02-18 07:54"),julianday("2021-02-18 15:48"),1,"WORK");
.header on
.mode column
SELECT strftime('%W',clock_in) AS 'weekofyear',
time(clock_in) as "IN",
time(clock_out) as "OUT",
CASE when lunch = 1 then round(Cast (( JulianDay(clock_out) - JulianDay(clock_in)) * 24 - .5 As REAL),2)
when lunch = 0 then round(Cast (( JulianDay(clock_out) - JulianDay(clock_in)) * 24 As REAL),2)
END as "total_time",
sum("total_time")
FROM timecard
GROUP BY "weekofyear";
Esta é a saída do comando.
weekofyear IN OUT total_time sum("total_time")
---------- ---------- ---------- ---------- -----------------
07 08:00:00 16:00:00 8.0 0.0
Estou tentando obter o total de horas para a semana do ano. Não tenho certeza do que estou fazendo de errado. Eu sou novo na instrução case em SQL e SQL em geral.
Obrigado pelo seu tempo