一道sql 关于pivot的面试题

分析:其实它是对时间月份行转列的

表结构设计:

一道sql 关于pivot的面试题

结果:

select Name,moth,ISNULL([01],0) as Value1,ISNULL([02],0) as Value2,ISNULL([03],0) as Value3 from (
select a.Name,CONVERT(varchar(4),moth,120) as moth,CONVERT(varchar(2),moth,100) as moth2,number from Table_Type as a
left join Table_SHUJU as b on a.id=b.id
) as table1 pivot (sum(number) for moth2 in([01],[02],[03])) as table2

 

效果图:

一道sql 关于pivot的面试题

 

相关文章:

  • 2021-12-06
  • 2021-09-18
  • 2021-07-01
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-23
  • 2021-10-22
  • 2022-12-23
  • 2021-06-17
  • 2021-10-01
  • 2021-08-04
相关资源
相似解决方案