我更改了我的sql request
根據哪個widget value is selected
。 我糾正根據我的問題這一要求enter link description here 這下我的要求:如何使用case子句創建sql請求
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
像我的數據源到真知晶球雲。 你能告訴我我的錯在哪?
如果我們認爲這是您的確切SQL ...山後缺少逗號。選擇...'提取(從「Facturation」月份)作爲mt,' – xQbert
我現在加了它,它返回這個錯誤:錯誤:列「LRU」不存在 位置:8 – vero
可能的[如何做SQL請求使用CASE](https://stackoverflow.com/questions/45589804/how-to-do-an-sql-request-using-case) – yanman1234