Posted By

dsoms on 04/09/11


Tagged

mysql count countif


Versions (?)

Countif in MySQL


 / Published in: MySQL
 

  1. SELECT
  2. id,
  3. sum(if (`user_type` = 1, 1, 0)) as COUNT_TYPE1,
  4. sum(if (`user_type` = 2, 1, 0)) as COUNT_TYPE2,
  5. sum(if (`user_type` = 3, 1, 0)) as COUNT_TYPE3,
  6. sum(if (`user_type` = 4, 1, 0)) as COUNT_TYPE4
  7. FROM users
  8. GROUP BY id

Report this snippet  

You need to login to post a comment.