美文网首页
SQL 合并分组 Stuff

SQL 合并分组 Stuff

作者: DrS6 | 来源:发表于2019-10-10 10:10 被阅读0次

    select * from ColorBox



    select

    a.Code ,

    STUFF((SELECT ','+rtrim(Color) FROM ColorBox WHERE a.Code = Code  ORDER BY Code FOR XML PATH('')),1,1,'')

    as Color,b.ccount as ColorCount

    from ColorBox a

    inner join (

    select Code,count(color) as ccount from ColorBox group by Code

    )b on b.Code = a.Code

    group by a.Code,b.ccount


    相关文章

      网友评论

          本文标题:SQL 合并分组 Stuff

          本文链接:https://www.haomeiwen.com/subject/ftdopctx.html