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如何合并?

解决方案 »

  1.   

    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
    )
    group by paymenttype
      

  2.   

    贴建表及插入记录的SQL
    使用的表都不同
      

  3.   

    是这样?
    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
      

  4.   

    错误信息是什么?加上别名再试。
    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
      

  5.   

    加入别名a group by PaymentType
      

  6.   


    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这样可以了
      

  7.   

    弱弱的问下:WWWWB与WWWWA是一个人还是2个人?