一道sql 关于pivot的面试题
2017-02-17 18:37
274 查看
分析:其实它是对时间月份行转列的
表结构设计:
结果:
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的面试题
- 一道SQL语句面试题,关于group by的
- 一道SQL语句面试题,关于group by
- 关于一道sql的面试题 (非常精典) (转)
- 关于一道sql的面试题 (非常精典)
- 一道SQL语句面试题,关于group by
- 关于FOR循环的一道面试题
- 一道sql面试题的多种解答
- 今天没做起的一道SQL面试题
- 开始学习SQL了,请高手回答帮一下小菜鸟,一道面试题
- 关于一道面试题的源代码解答
- 一道SQL题...(关于树型结构的在关系表中的存储及其应用处理)
- 一道关于静态变量的初始化顺序面试题
- 一道sql面试题附答案
- 一道sql面试题附答案
- 关于一道面试题
- 关于一道微软面试题的思考
- 一道关于宏的面试题及解答
- 一道关于字符串操作的面试题
- 一道SQL语句面试题