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

    成了这样的效果:

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

  • 相关阅读:
    yum install mysql.i686
    firefox无法浏览flash的解决方案
    vb.net如何打开指定文件
    XML文件操作的简单类
    window server 安装与卸载
    常用的sql语句
    with进行递归表
    常用js
    调用Google的自动翻译
    MySQl 总结知识
  • 原文地址:https://www.cnblogs.com/pigddyou/p/2734091.html
Copyright © 2011-2022 走看看