Statistical analysis returns the result of multiple situations when case usage of sql

select
    sum(case when ismm.smm_type = '1' and ismm .smm_status = '0' then ismm.smm_num else 0 end) as monthPurchaseNum,
    sum(case when ismm.smm_type = '2' and (ismm.smm_status = '0' or ismm.smm_status = '4') then ismm.smm_num else 0 end) as monthSelfNum,
    sum(case when ismm.smm_status = '1' or (ismm.smm_status = '4' and ismm.smm_inventory_status = '2') then ismm.smm_num else 0 end) as monthOutNum,
    sum(case when ismm .smm_status = '2' then ismm.smm_num else 0 end) as monthLoseNum,
    sum(case when ismm .smm_status = '3' then ismm.smm_num else 0 end) as monthReturnNum
from isp_stock ismm
left join isp_gener igpad on igpad.id = ismm.smm_id
left join isp_bas ibs on ibs.lifnr = igpad.sup_id
where ismm.delete = '0' and ismm.smm_status = '1'

Guess you like

Origin blog.csdn.net/qq_40390762/article/details/124986852