How to get multiple counts with one SQL query?

后端 未结 9 2022
清酒与你
清酒与你 2020-11-22 14:03

I am wondering how to write this query.

I know this actual syntax is bogus, but it will help you understand what I am wanting. I need it in this format, because it i

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 14:11

    For MySQL, this can be shortened to:

    SELECT distributor_id,
        COUNT(*) total,
        SUM(level = 'exec') ExecCount,
        SUM(level = 'personal') PersonalCount
    FROM yourtable
    GROUP BY distributor_id
    

提交回复
热议问题