Select B.PaymentType as paymenttype,Sum(B.PaymentAmount) As SPaymentAmount From Trans A INNER JOIN TransPayment B
ON A.TransID = B.TransID Where B.BusinessDate Between '2010-12-15' And '2010-12-15' And A.TransStatus In (2, 3, 4)
Group By B.PaymentType
union all
SELECT deposittype as paymenttype,sum(amount)as SPaymentAmount
FROM depositdetail where TransDate Between '2010-12-15 00:00:00' And '2010-12-15 23:59:59' and transstatus=1
group by deposittypeResult:
'Cash', 37.9000
'DEPOSIT', 32.8000
'EPS', 100.0000
'VISA', 50.0000
'Cash', 550.0000
'MASTERS ', 50.0000
'VISA ', 50.0000如何合并?
from (
Select B.PaymentType as paymenttype,Sum(B.PaymentAmount) As SPaymentAmount From Trans A INNER JOIN TransPayment B
ON A.TransID = B.TransID Where B.BusinessDate Between '2010-12-15' And '2010-12-15' And A.TransStatus In (2, 3, 4)
Group By B.PaymentType
union all
SELECT deposittype as paymenttype,sum(amount)as SPaymentAmount
FROM depositdetail where TransDate Between '2010-12-15 00:00:00' And '2010-12-15 23:59:59' and transstatus=1
group by deposittype
)
group by paymenttype
使用的表都不同
select PaymentType,sum(SPaymentAmount) from (
Select B.PaymentType as paymenttype,Sum(B.PaymentAmount) As SPaymentAmount From Trans A INNER JOIN TransPayment B
ON A.TransID = B.TransID Where B.BusinessDate Between '2010-12-15' And '2010-12-15' And A.TransStatus In (2, 3, 4)
Group By B.PaymentType
union all
SELECT deposittype as paymenttype,sum(amount)as SPaymentAmount
FROM depositdetail where TransDate Between '2010-12-15 00:00:00' And '2010-12-15 23:59:59' and transstatus=1
group by deposittype) a group by PaymentType
select paymenttype,sum(SPaymentAmount)
from (
Select B.PaymentType as paymenttype,Sum(B.PaymentAmount) As SPaymentAmount From Trans A INNER JOIN TransPayment B
ON A.TransID = B.TransID Where B.BusinessDate Between '2010-12-15' And '2010-12-15' And A.TransStatus In (2, 3, 4)
Group By B.PaymentType
union all
SELECT deposittype as paymenttype,sum(amount)as SPaymentAmount
FROM depositdetail where TransDate Between '2010-12-15 00:00:00' And '2010-12-15 23:59:59' and transstatus=1
group by deposittype
) t
group by paymenttype
select c.paymenttype,c.SPaymentAmount
from (
Select B.PaymentType as paymenttype,Sum(B.PaymentAmount) As SPaymentAmount From Trans A INNER JOIN TransPayment B
ON A.TransID = B.TransID Where B.BusinessDate Between '2010-12-15' And '2010-12-15' And A.TransStatus In (2, 3, 4)
Group By B.PaymentType
union all
SELECT deposittype as paymenttype,sum(amount)as SPaymentAmount
FROM depositdetail where TransDate Between '2010-12-15 00:00:00' And '2010-12-15 23:59:59' and transstatus=1
group by deposittype
)c
group by c.paymenttype这样可以了