How to group by with a special condition

前端 未结 3 1901
旧巷少年郎
旧巷少年郎 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:19

    @bfavaretto is nice (+1 to him), but if you don't know about username prefix or they are different you can go with something like:

    GROUP BY CASE
                 WHEN REGEXP_LIKE(username, '^\d+$') THEN 'GRP_OTHERS'
                                                     ELSE username
             END
    

提交回复
热议问题