2013-07-01 91 views
0
select '' as xxx,pawn.propawn_price as yyy from product_pawn pawn 
inner join product_history history on history.propawn_id = pawn.propawn_id 
and history.prohistory_status = '0' 
union 
select pawn.propawn_price * 8/100 as xxx,'' as yyy from product_pawn pawn 
inner join product_history history on history.propawn_id = pawn.propawn_id 
and history.prohistory_status = '1' 
union 
select pawn.propawn_price + pawn.propawn_price * 8/100 as xxx,'' as yyy 
from product_pawn pawn 
inner join product_history history on history.propawn_id = pawn.propawn_id 
and history.prohistory_status = '2' 
union 
select prosell_pricesell as xxx,'' as yyy from product_sell 
where prosell_status = '5' 

結果SQL服務器和工會

XXX YYY

0 --- 900

0 --- 800

700 --- 0

0 - - 100

500 --- 0

我想總結xxx和總和YYY

回答

1

你可以嘗試這樣的...

SELECT Sum(xxx) as xxx,Sum(yyy) as yyy from (
    select '' as xxx,pawn.propawn_price as yyy from product_pawn pawn 
    inner join product_history history on history.propawn_id = pawn.propawn_id 
    and history.prohistory_status = '0' 
    union 
    select pawn.propawn_price * 8/100 as xxx,'' as yyy from product_pawn pawn 
    inner join product_history history on history.propawn_id = pawn.propawn_id 
    and history.prohistory_status = '1' 
    union 
    select pawn.propawn_price + pawn.propawn_price * 8/100 as xxx,'' as yyy 
    from product_pawn pawn 
    inner join product_history history on history.propawn_id = pawn.propawn_id 
    and history.prohistory_status = '2' 
    union 
    select prosell_pricesell as xxx,'' as yyy from product_sell 
    where prosell_status = '5') t 
+0

我忘了你 – Harajukuzz

+0

@Harajukuzz歡迎不要表名哈哈THX忘記接受它作爲答案,如果它幫助你 –