且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从现有数据创建新的逗号分隔列?

更新时间:2023-12-01 19:26:46

您可以使用函数 concat_ws 跳过 null 值.

You can use the function concat_ws which skips the null values.

select username,
concat_ws(','
         ,case when admin_for_blog is not null then 'ADMIN' end
         ,case when editor_for_blog is not null then 'EDITOR' end
         ,case when author_for_blog is not null then 'AUTHOR' end
         )
from account