getting count from the same column in a mysql table?

后端 未结 4 793
野趣味
野趣味 2021-01-03 00:07

I wanted to a count of the same field for different values for example:

user{user_id, gender}

Gender can have obviously male or

4条回答
  •  轮回少年
    2021-01-03 00:32

    Try this query -

    SELECT
      COUNT(IF(gender = 'M', User_id, NULL) males,
      COUNT(IF(gender = 'F', User_id, NULL) females
    FROM
      User
    

提交回复
热议问题