日期:2014-05-18 浏览次数:20558 次
select col,count(*) from(select col1 as col from tb union all select col2 from tb unioin all select col3 from tb) as t group by col
------解决方案--------------------
if object_id('[table4]') is not null drop table [table3] create table [table4]([col1] VARCHAR(32),[col2] VARCHAR(32),[col3] VARCHAR(32)) insert [table4] select 'a ','a ','b' union all select 'c ','b', 'a' union all select 'b','b' ,'b' SELECT col,sum(1) value FROM( SELECT col1 AS col FROM table4 UNION ALL SELECT col2 AS col FROM table4 UNION ALL SELECT col3 AS col FROM table4) tb GROUP BY col col value ---- ----- a 3 b 5 c 1