日期:2014-05-17 浏览次数:20531 次
select ListID,[1] 'A',[2] 'B',[3] 'C',[4] 'D',[5] 'E'
from
(select ListID,VoteValue,count(1) 'ct'
from [tab] group by ListID,VoteValue) t
pivot(max(ct) for VoteValue in([1],[2],[3],[4],[5])) p
select ListID,
isnull([1],0) 'A',
isnull([2],0) 'B',
isnull([3],0) 'C',
isnull([4],0) 'D',
isnull([5],0) 'E'
from
(select ListID,VoteValue,count(1) 'ct'
from [tab] group by ListID,VoteValue) t
pivot(max(ct) for VoteValue in([1],[2],[3],[4],[5])) p