日期:2014-05-17 浏览次数:20555 次
select * into #T from (
select 1 A, 3 B
union all select 1 ,3
union all select 1 ,3
union all select 3 ,1
union all select 1 ,2
union all select 4 ,1
)a
select * From #t
select a,b,sum(c)c from (
select a,b,count(1)c From #t where a=1 group by a,b
union
select b,a,count(1)c From #t where b=1 group by a,b
)a
group by a,b
/*
a b c
----------- ----------- -----------
1 2 1
1 3 4
1 4 1
*/