I'm trying to do an SQL request
using a clause case
, but always it return this error:
ERROR: syntax error at or near "CASE"
My request is the following:
SELECT distinct extract(month from "Facturation") as month, "LRU", "Client"
from "foundry_sync"."data"
CASE month
WHEN "month" =1 THEN
select avg("Montant_fac_eur") as c1 where "Facturation" between 1 and 6
when "month" =2 THEN
select avg("Montant_fac_eur") as c2 where "Facturation" between 2 and 7
when "month" =3 THEN
select avg("Montant_fac_eur") as c3 where "Facturation" between 3 and 8
when "month" = 4 then
select avg("Montant_fac_eur") as c4 where "Facturation" between 4 and 9
when "month"=5 THEN
select avg("Montant_fac_eur") as c5 where "Facturation" between 5 and 10
when "month"=6 THEN
select avg("Montant_fac_eur") as c6 where "Facturation" between 6 and 11
when "month"=7 THEN
select avg("Montant_fac_eur") as c7 where "Facturation" between 7 and 11
else ''
END
group by "LRU", "Client", "Facturation"
order by "Client", "month"
I'm using MySQL
.
Facturation
is a date
.
Can someone please tell me me where's my fault ? Thank you.