• SQL Server中的行转列


    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

    更多技术交流+QQ:318617848
  • 相关阅读:
    学习进度14
    学习进度13
    学习进度12
    2020.12.01 表单元素
    2020.12.02 表单属性
    2020.12.04
    2020.12.06
    2020.12.07
    2020.12.08 URL
    2020.12.09
  • 原文地址:https://www.cnblogs.com/huyaguang/p/5763722.html
Copyright © 2020-2023  润新知