select ID,sum(case when DATEDIFF(week,now(),销售日期)=1 then 销售金额 end) 第一周,sum(case when DATEDIFF(week,now(),销售日期)=2 then 销售金额 end) 第二周,sum(case when DATEDIFF(week,now(),销售日期)=3 then 销售金额 end) 第三周,sum(case when DATEDIFF(week,now(),销售日期)=4 then 销售金额 end) 第四周 from 表 where DATEDIFF(week,now(),销售日期)<5 group by ID