我根据sql request
更改了widget value is selected
。
我根据我的问题enter link description here更正了此请求
这是根据我的要求:
SELECT "LRU", "Client", extract(month from "Facturation") as mt
CASE {{w_widget6.selectedValue}}
WHEN {{w_widget6.selectedValue}}=1 THEN
(select avg("Montant_fac_eur") as c1 from "foundry_sync"."data" where "month" between 1 and 6)
when {{w_widget6.selectedValue}} =2 THEN
(select avg("Montant_fac_eur") as c2 from "foundry_sync"."data" where "month" between 2 and 7)
when {{w_widget6.selectedValue}} =3 THEN
(select avg("Montant_fac_eur") as c3 from "foundry_sync"."data" where "month" between 3 and 8)
when {{w_widget6.selectedValue}} = 4 THEN
(select avg("Montant_fac_eur") as c4 from "foundry_sync"."data" where "month" between 4 and 9)
when {{w_widget6.selectedValue}} =5 THEN
(select avg("Montant_fac_eur") as c5 from "foundry_sync"."data" where "month" between 5 and 10)
when {{w_widget6.selectedValue}} =6 THEN
(select avg("Montant_fac_eur") as c6 from "foundry_sync"."data" where "month" between 6 and 11)
when {{w_widget6.selectedValue}} =7 THEN
(select avg("Montant_fac_eur") as c7 from "foundry_sync"."data" where "month" between 7 and 12)
END;
from "foundry_sync"."data"
group by "LRU", "Client"
但我总是有同样的错误:
ERROR: syntax error at or near "CASE"
Position: 68
我正在使用foundry-postgate
类似我的数据来源进入Palantir Cloud。
你能告诉我哪里是我的错吗?
答案 0 :(得分:1)
就我个人而言,重构整个查询:
month
是foundry_Sync.data 。
SELECT LRU
, Client
, extract(month from Facturation) as mt
, avg("Montant_fac_eur") AVG_MONT_FAC_EUR
FROM foundry_sync.data FSD
WHERE `month` between 0+{{w_widget6.selectedValue}} and 5+{{w_widget6.selectedValue}}
GROUP BY LRU, Client, extract(month from Facturation)