码迷,mamicode.com
首页 > 数据库 > 详细

行转列SQL语句

时间:2016-08-17 12:01:12      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

select top 10 * from schedule_month where years=2016 and months=7 and managerid=45
SELECT top 10 cast(years AS varchar) + ‘-‘ + RIGHT(‘0‘ + CAST(months AS varchar), 2) + ‘-‘ + RIGHT(‘0‘ + REPLACE(days,
‘day‘, ‘‘), 2) AS trueday, job_title_id, managerid, years, months, days, dayvalue
FROM (SELECT job_title_id, managerid, years, months, day1, day2, day3, day4, day5, day6, day7, day8, day9,
day10, day11, day12, day13, day14, day15, day16, day17, day18, day19, day20, day21, day22,
day23, day24, day25, day26, day27, day28, day29, day30, day31
FROM schedule_month) p UNPIVOT (dayvalue FOR days IN (day1, day2, day3, day4, day5, day6, day7,
day8, day9, day10, day11, day12, day13, day14, day15, day16, day17, day18, day19, day20, day21, day22,
day23, day24, day25, day26, day27, day28, day29, day30, day31))
AS unpvt/*years=@years and months=@months*/技术分享

行转列SQL语句

标签:

原文地址:http://www.cnblogs.com/sulong/p/5779141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!