How to group by with a special condition

前端 未结 3 1868
旧巷少年郎
旧巷少年郎 2021-01-11 23:47

Currently when I issue this SQL, it gets the distinct username.

I have some distinct usernames, which represent groups, e.g. GRP_BSN.

I would li

3条回答
  •  再見小時候
    2021-01-12 00:04

    Not very efficient, but should work:

    SELECT 
        CASE WHEN username LIKE 'GRP%' THEN username ELSE 'GRP_OTHERS' END AS username, 
        COUNT(*)
    FROM host
    WHERE seq BETWEEN 0 AND 2000
    GROUP BY CASE WHEN username LIKE 'GRP%' THEN username ELSE 'GRP_OTHERS' END;
    

提交回复
热议问题