博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server中的行转列
阅读量:5038 次
发布时间:2019-06-12

本文共 1303 字,大约阅读时间需要 4 分钟。

with tt as(select s.MorOrAftOrEve, case s.MorOrAftOrEve when 1 then '上午' when 2 then '下午' else '晚上' end as MAE ,'第'+cast(s.Section as varchar(10))+'节' as JC,

(CASE s.WeekDay when '星期一' then s.ProjectID else 0 end) as week1,
(CASE s.WeekDay when '星期二' then s.ProjectID else 0 end) as week2,
(CASE s.WeekDay when '星期三' then s.ProjectID else 0 end) as week3,
(CASE s.WeekDay when '星期四' then s.ProjectID else 0 end) as week4,
(CASE s.WeekDay when '星期五' then s.ProjectID else 0 end) as week5,
(CASE s.WeekDay when '星期六' then s.ProjectID else 0 end) as week6,
(CASE s.WeekDay when '星期日' then s.ProjectID else 0 end) as week7
from dbo.EDU_ScheduleManager s where s.ClassID=#ClassID# and s.SchoolID=#SchoolID#)
select mae,jc,
(select CourseName from dbo.EDU_Course where id=sum(week1)) as w1,
(select CourseName from dbo.EDU_Course where id=SUM(week2)) as w2,
(select CourseName from dbo.EDU_Course where id=SUM(week3)) as w3,
(select CourseName from dbo.EDU_Course where id=SUM(week4)) as w4,
(select CourseName from dbo.EDU_Course where id=SUM(week5)) as w5,
(select CourseName from dbo.EDU_Course where id=SUM(week6)) as w6,
(select CourseName from dbo.EDU_Course where id=SUM(week7)) as w7 from tt
group by mae,jc,MorOrAftOrEve order by MorOrAftOrEve asc

转载于:https://www.cnblogs.com/huyaguang/p/5763722.html

你可能感兴趣的文章
【读书笔记】《HTTP权威指南》:Web Hosting
查看>>
Inoodb 存储引擎
查看>>
数据结构之查找算法总结笔记
查看>>
Linux内核OOM机制的详细分析
查看>>
Android TextView加上阴影效果
查看>>
Requests库的基本使用
查看>>
C#:System.Array简单使用
查看>>
C#inSSIDer强大的wifi无线热点信号扫描器源码
查看>>
「Foundation」集合
查看>>
算法时间复杂度
查看>>
二叉树的遍历 - 数据结构和算法46
查看>>
类模板 - C++快速入门45
查看>>
[转载]JDK的动态代理深入解析(Proxy,InvocationHandler)
查看>>
centos7 搭建vsftp服务器
查看>>
RijndaelManaged 加密
查看>>
Android 音量调节
查看>>
HTML&CSS基础学习笔记1.28-给网页添加一个css样式
查看>>
windows上面链接使用linux上面的docker daemon
查看>>
Redis事务
查看>>
Web框架和Django基础
查看>>