try
create table #t (a int,b int,c int,d int)insert into #t select 1,2,3,4
insert into #t select 1,2,3,4
insert into #t select 0,1,4,3
select count(*) 次数,a from(
select a from #t
union all
select b from #t
union all
select c from #t
union all
select d from #t) as t
group by a
create table #t (a int,b int,c int,d int)insert into #t select 1,2,3,4
insert into #t select 1,2,3,4
insert into #t select 0,1,4,3
select count(*) 次数,a from(
select a from #t
union all
select b from #t
union all
select c from #t
union all
select d from #t) as t
group by a
insert into #t select 8,1,4,2
insert into #t select 0,1,4,3
select count(*) 次数,a from(
select a from #t
union all
select b from #t
union all
select c from #t
union all
select d from #t) as t
group by adrop table #t1 0
3 1
2 2
2 3
3 4
1 8