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` = 3, 1, 0)) as `heart_count` , sum(if(`reward_type` = 5 and `item_type` = 1, 1, 0)) as `straight_line` , sum(if(`reward_type` = 5 and `item_type` = 2, 1, 0)) as `range` , sum(if(`reward_type` = 5 and `item_type` = 3, 1, 0)) as `choice` , sum(if(`reward_type` = 5 and `item_type` = 4, 1, 0)) as `one_block` , sum(if(`reward_type` = 5 and `item_type` = 5, 1, 0)) as `shuffle` FROM `statistics_buy_shop` group by date(`create_time`); | cs |