zoukankan      html  css  js  c++  java
  • MSSQL 行转列

    示例:

    原本是同一个学生的2条记录,把它行转列后:

    select                    studentnid                           
                                 ,max(case StudentSourceTypeNid when'1' then SourcePrimaryKey else '0' end) vipSourcePrimaryKey,
                                 max(case StudentSourceTypeNid when'1' then SourceDate else null end) vipSourceDate, 
                                 max(case StudentSourceTypeNid when'2' then SourcePrimaryKey else '0' end) stmsSourcePrimaryKey,
                                 max(case StudentSourceTypeNid when'2' then SourceDate else null end) stmsSourceDate,
                                 max(case StudentSourceTypeNid when'3' then SourcePrimaryKey else '0' end) webSourcePrimaryKey,
                                 max(case StudentSourceTypeNid when'3' then SourceDate else null end) webSourceDate
                                from 
                                 (
                                 select student.*,
                                stuSource.SourcePrimaryKey,
                                stuSource.SourceDate,
                                stuSource.StudentSourceTypeNid
                                 from dbo.MEM_Student as student
                                inner join dbo.MEM_StudentSource as stuSource
                                on student.studentnid=stuSource.studentnid
                                 ) as tb
                                where studentnid=@studentnid
                                group by studentnid,studentname,sex

    成了这样的效果:

    以上就是代码了,我懂的。

  • 相关阅读:
    mysql 常用命令行
    mysql常用命令
    Mac os安装wget
    linux下给文件夹或者目录赋权
    Python学习相关资料
    Mac常用的一些操作
    Mac os安装git及 git及githup的使用
    Linux磁盘占用100%解决方法
    page-break-after:always
    工具
  • 原文地址:https://www.cnblogs.com/pigddyou/p/2734091.html
Copyright © 2011-2022 走看看