Mysql

mysql sum if 사용

NaHyungMin 2018. 10. 2. 18:46

아이템 구매 일자별로 통계 확인


1
2
3
4
5
6
7
8
9
SELECT date(`create_time`) as `create_time`
    , sum(if(`reward_type` = 310)) as `heart_count`
    , sum(if(`reward_type` = 5 and `item_type` = 110)) as `straight_line`
    , sum(if(`reward_type` = 5 and `item_type` = 210)) as `range`
    , sum(if(`reward_type` = 5 and `item_type` = 310)) as `choice`
    , sum(if(`reward_type` = 5 and `item_type` = 410)) as `one_block`
    , sum(if(`reward_type` = 5 and `item_type` = 510)) as `shuffle`
FROM `statistics_buy_shop`
group by date(`create_time`);



cs