0
I need help to return in an SQL the amount you have of each day of the week in a period of 1 month, for example in the month 06/2021 has 4 Mondays,5 Tuesdays,5 Wednesdays...etc. I need to know the amount of every day of the week, because I need to average that amount. I tried several ways but it didn’t work, I need it to be in SQL Firebird. Thank you. Below this one of the forms I tried, it returns to every day of the week the amount of 560:
SELECT sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_segunda,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_terca,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_quarta,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_quinta,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_sexta,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_sabado,
sum(iif(EXTRACT(WEEKDAY FROM N.DTEMISSAO) = 1, 1, 0)) qt_domingo
FROM NOTA N
WHERE N.DTEMISSAO BETWEEN '01.06.2021' AND '30.06.2021'
make a
group by
by date (per day in your case)– Ricardo Pontual
Did not work, gave error: Cannot use an Aggregate Function in a GROUP BY clause.
– Amanda Martins
@Ricardopunctual put your code as answer, if it doesn’t work just delete
– Erick Luz
what is the difference of the column dtemitted to outdate?
– Erick Luz
No, I wrote it wrong, I’ll fix it
– Amanda Martins