/*
名称 prod_name ,
规格 spec,
价格 price
表名 table_name
*/
declare @col_str nvarchar(4000)
set @col_str=''
select @col_str=@col_str+',sum(case when spec='''' + spec +'''then price else 0 end as sp_' + spec
from (select distinct spec from table_name ) q_spec
exec ('select prod_name '+ @col_str + 'from table_name group by prod_name order by prod_name')