将sql值分配给临时值

时间:2017-06-12 12:48:19

标签: sql oracle

我正在尝试使用SQL将值SUM(Price)分配到变量中,以便在我的后续选择中选择我可以使用SUM(Price)并将其相乘。

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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