开发者社区 问答 正文

SQL:如何从具有字符串值的列中查找特定类别值的计数

SQL:如何从具有字符串值的列中查找特定类别值的计数

展开
收起
贺贺_ 2019-12-04 21:52:10 369 分享 版权
1 条回答
写回答
取消 提交回答
  • 如果您试图获得用逗号分隔的Category Ids,可以使用string_split函数获得不同的category_id

    with cte as (
        select 1 as id, '3,2' as category union all
        select 2, '1' union all
        select 3, '4,3,2' union all
        select 4, '2,1' union all
        select 5, '1,4' union all
        select 6, '2,3,4' 
    )select count(distinct(value)) as category from cte
    cross apply string_split(cte.category, ',');
    
    2019-12-04 21:54:11
    赞同 展开评论
问答分类:
SQL
问答标签:
问答地址: