0
我對我的查詢沒有什麼問題,我想在單選語句中顯示2 union all
,但只有union all正在工作。來自同一表-H2數據庫的兩個聯盟
工作查詢:
select '' as Total, product, price,sellprice,
openingstock as openingStock, openingstock*price as op_value,
receipts as receipts, receipts*price as re_value,
totalstock as totalstock, totalstock*price as ts_value,
sales as sales, sales*sellprice as s_value,
return as returns,return*sellprice as rt_value,
closingstock as closingstock, closingstock*price as cl_value
from purchase_table where date between '2017-04-01' and '2017-05-30'
union all
select orgname , 'Total', sum(price),sum(sellprice),
sum(openingstock) as openingStock, sum(openingstock*price) as op_value,
sum(receipts) as receipts, sum(receipts*price) as re_value,
sum(totalstock) as totalstock, sum(totalstock*price) as ts_value,
sum(sales) as sales, sum(sales*sellprice) as s_value,
sum(return) as returns,sum(return*sellprice) as rt_value,
sum(closingstock) as closingstock, sum(closingstock*price) as cl_value
from purchase_table where date between '2017-04-01' and '2017-05-30' group by orgname order by closingstock asc
當我添加另一個聯盟所有它不工作
select '' as Total, product, price,sellprice,
openingstock as openingStock, openingstock*price as op_value,
receipts as receipts, receipts*price as re_value,
totalstock as totalstock, totalstock*price as ts_value,
sales as sales, sales*sellprice as s_value,
return as returns,return*sellprice as rt_value,
closingstock as closingstock, closingstock*price as cl_value
from purchase_table where date between '2017-04-01' and '2017-05-30'
union all
select orgname , 'Total', sum(price),sum(sellprice),
sum(openingstock) as openingStock, sum(openingstock*price) as op_value,
sum(receipts) as receipts, sum(receipts*price) as re_value,
sum(totalstock) as totalstock, sum(totalstock*price) as ts_value,
sum(sales) as sales, sum(sales*sellprice) as s_value,
sum(return) as returns,sum(return*sellprice) as rt_value,
sum(closingstock) as closingstock, sum(closingstock*price) as cl_value
from purchase_table where date between '2017-04-01' and '2017-05-30' group by orgname order by closingstock asc
union all
select '' , '', sum(price),sum(sellprice),
sum(openingstock) as openingStock, sum(openingstock*price) as op_value,
sum(receipts) as receipts, sum(receipts*price) as re_value,
sum(totalstock) as totalstock, sum(totalstock*price) as ts_value,
sum(sales) as sales, sum(sales*sellprice) as s_value,
sum(return) as returns,sum(return*sellprice) as rt_value,
sum(closingstock) as closingstock, sum(closingstock*price) as cl_value
from purchase_table
我究竟做錯了什麼,請由第二幫助
感謝的迴應,但我想在第二工會ASC選擇語句 –
答案更新增加了選擇,訂購第二有序 – scaisEdge