case when 使用

case when


 select
            sum(
                    case when item_first_cate_cd = 9987 then after_prefr_amount
                            else 0.0 end) as phone_amount,
            sum(
                    case when item_first_cate_cd in(174, 670) then
                                    before_prefr_amount else 0.0 end) as
            compute_amount,
            sum(
                    case when item_first_cate_cd = 1315 then 1 else 0 end) as
            clothing_ord_num
    from
            gdm.gdm_m04_ord_det_sum
    where
            dt                     >= '2016-11-11'
            and sale_ord_dt         = '2016-11-11'
            and sale_ord_valid_flag = 1
            and item_first_cate_cd in(9987, 174, 670, 1315)
    group by
            sale_ord_dt

results for ""

    No results matching ""