首页 > 数据库技术 > 详细

SQL行专列

时间:2014-03-23 10:51:35      阅读:421      评论:0      收藏:0      [点我收藏+]

一张表

bubuko.com,布布扣
查询结果为
bubuko.com,布布扣
1
2
3
4
5
--行转列
select  years,(select amount from Tb_Amount as A where month=1 and A.years=Tb_Amount.years)as m1,
(select amount from Tb_Amount as A where month=2 and A.years=Tb_Amount.years)as m2,
(select amount from Tb_Amount as A where month=3 and A.years=Tb_Amount.years)as m3
from  Tb_Amount group by  years

 

SQL行专列,布布扣,bubuko.com

SQL行专列

原文:http://www.cnblogs.com/Warmsunshine/p/3618701.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!