select xx.ped_mcname,xx.ped_breedid,xx.ped_breedname,sum(xx.ped_auditing_price) price,
case datepart(qq,xx.ped_coltime)
when 1 then '第一季度'
when 2 then '第二季度'
when 3 then '第三季度' end
from pc_priceexp_data xx group by xx.ped_mcname,xx.ped_breedid,xx.ped_breedname,
datepart(qq,xx.ped_coltime)
select 名字,价格,
第一季度 =sum(case when datepart(qq,datecol)= 1 then ... else... end),
第二季度 =sum(case when datepart(qq,datecol)= 2 then ... else... end),
第三季度 =sum(case when datepart(qq,datecol)= 3 then ... else... end)
from ta
group by 名字,价格
select 名字,sum(价格),
sum(case when month(时间) between 1 and 3 then 数量 else 0 end) 第一季度,
sum(case when month(时间) between 4 and 6 then 数量 else 0 end) 第二季度
..
from tb
group by 名字