2017-06-12 97 views
1

我想將值SUM(Price)分配到一個變量使用SQL,以便在我的後續選擇我可以使用SUM(Price)並乘以它。分配sql值到一個臨時值

SELECT "Total", SUM(PRICE), "pricing" =0 , "Trend" =0 
    FROM Products 
UNION ALL 
SELECT "Forecast", SUM(ProductID) as test, "pricing" = SUM(PRICE) *2, "Trend" = 0 
    FROM Products 

但是,輸出給了我這個。我究竟做錯了什麼?

enter image description here

+1

請您真正使用的數據庫標記您的問題。 –

+0

目前尚不清楚你正在努力完成什麼。你的預期結果是什麼? – SchmitzIT

+0

Hihi我正在使用oracle apex。它綁定到一個oracle數據庫。 – Adam

回答

1

你只是想這樣的事情:

select 'total', sum(Price), '0' as Pricing, '0' as Trend 
from Products 
union all 
select 'forcast',sum(ProductID), sum(price)*2, '0' 
from Products 
+0

這工作很好!非常感謝! – Adam

0

試試這個

SELECT 'Total', SUM(PRICE), 'PRICING'=0, 'TREND'=0 FROM products 
UNION ALL 
SELECT 'FORECAST', SUM(ProductId), SUM(PRICE)*2, 0 as TREND FROM products