SELECT query with CASE condition and SUM()

前端 未结 5 2322
遥遥无期
遥遥无期 2020-12-03 02:59

I\'m currently using these sql statements. My table has the field CPaymentType which contains \"Cash\" or \"Check\". I can sum up the amount of payments by executing 2 SQL s

5条回答
  •  没有蜡笔的小新
    2020-12-03 03:42

    select CPaymentType, sum(CAmount)
    from TableOrderPayment
    where (CPaymentType = 'Cash' and CStatus = 'Active')
    or (CPaymentType = 'Check' and CDate <= bsysdatetime() abd CStatus = 'Active')
    group by CPaymentType
    

    Cheers -

提交回复
热议问题