[英]Column does not Exist in postgresql?
我正在嘗試選擇查詢中的案例,並希望使用該案例在同一查詢中生成的數據列。
我的查詢是:
select order_id , order_item_id , sku ,merchant_payable as "Value Get" ,
case when name like 'Rise%'
then amount-(((amount*12.14)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Masha%'
then amount-(((amount*9.10)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Bboy%'
then amount-(((amount*14.17)/100)+ ((amount*3.08)/100) + 51.30)
end as "Value Should Get" ,
"Value Should Get" - merchant_payable
from meta.paytm_payment as ppo
where
case when name like 'Rise%'
then amount-(((amount*12.14)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Masha%'
then amount-(((amount*9.10)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Bboy%'
then amount-(((amount*14.17)/100)+ ((amount*3.08)/100) + 51.30)
end > merchant_payable
order by order_created_at ;
就像是:
SELECT order_id ,
order_item_id ,
order_created_at ,
sku ,
"Value Get" ,
"Value Should Get" ,
"Value Should Get" - merchant_payable
FROM ( SELECT order_id ,
order_item_id ,
order_created_at ,
sku ,
merchant_payable AS "Value Get" ,
CASE WHEN name LIKE 'Rise%'
THEN amount - ( ( ( amount * 12.14 ) / 100 )
+ ( ( amount * 3.08 ) / 100 ) + 51.30 )
WHEN name LIKE 'Masha%'
THEN amount - ( ( ( amount * 9.10 ) / 100 )
+ ( ( amount * 3.08 ) / 100 ) + 51.30 )
WHEN name LIKE 'Bboy%'
THEN amount - ( ( ( amount * 14.17 ) / 100 )
+ ( ( amount * 3.08 ) / 100 ) + 51.30 )
END AS "Value Should Get"
FROM meta.paytm_payment AS ppo
) t
WHERE "Value Should Get" > merchant_payable
ORDER BY order_created_at;
您可以使用CTE
投影的重復,然后在WHERE
謂詞中使用它:
WITH myCte AS
(
select order_id , order_item_id , sku ,merchant_payable, order_created_at ,
case when name like 'Rise%'
then amount-(((amount*12.14)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Masha%'
then amount-(((amount*9.10)/100)+ ((amount*3.08)/100) + 51.30)
when name like 'Bboy%'
then amount-(((amount*14.17)/100)+ ((amount*3.08)/100) + 51.30)
end as "Value Should Get"
from paytm_payment as ppo
)
SELECT *, "Value Should Get" - merchant_payable AS "Nett"
from myCte
where "Value Should Get" > merchant_payable
order by order_created_at;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.