当前位置: 代码迷 >> Sql Server >> 怎么统计一行记录相同列值的总数?【】
  详细解决方案

怎么统计一行记录相同列值的总数?【】

热度:74   发布时间:2016-04-27 18:43:26.0
如何统计一行记录相同列值的总数?【在线等】
有这样的一条记录:
表名table1
id p1 p2 p3 p4 p5 p6
1 a c a b b d

输出结果为:
A B C D  
2 2 1 1

如何实现呢?在线等


------解决方案--------------------
SQL code
select p1,count(1)from (select p1 from table1union allselect p2 from table2union allselect p3 from table3union allselect p4 from table4union allselect p5 from table5union allselect p6 from table6) agroup by p1
  相关解决方案