具体语句我我就不写了,你参考这个
select custid, sum(case when YEAR(orderdate)=2002 then qty end) as [2002], sum(case when YEAR(orderdate)=2003 then qty end) as [2003], sum(case when YEAR(orderdate)=2004 then qty end) as [2004] from orders group by custid
select * from ( select custid,YEAR(orderdate) as years,qty from orders) as ord pivot(sum(qty) for years in([2003],[2004],[2005])) as p