zoukankan      html  css  js  c++  java
  • SQL Server 2005下的行列转化(简单)

    最近迷茫啦!什么都不相干!

    这些天看了些sql2005的知识,突然想到sql2005下的行列转化还没有结束。

    看了下原来的要求,简单的写出sql2005下的行列转化结果。

    代码如下:


    declare @table table
    (
     ID 
    int ,
     course 
    varchar(10),
     Point 
    int
    )


    insert into @table
    select 1 ,'语文',87
    union all
    select 1 ,'数学',98
    union all
    select 2,'语文',54
    union all
    select 3,'语文',97
    union all
    select 3,'数学',92
    union all
    select 4,'数学',86
    union all
    select 5 ,'数学',65
    union all
    select 6,'语文',76



    select ID ,
    isnull([数学],0)  [数学]  ,
    isnull([语文],0)  [语文]
      
    from @table
    pivot
    (
      
    sum(point)
      
    for course
      
    in ([数学],[语文])

    as pvt

    这个确实简单,但是,这是在知道了课程的情况下,要是不知道哪?(未完待续)

  • 相关阅读:
    属性选择器
    优先级
    hj_html&css
    hj_解决gpedit.msc不存在的问题
    hj_designPatterns
    hj_ssm
    hj-springmvc
    hj_mybatis
    hj_Python踩坑之旅
    hj_Python学习笔记
  • 原文地址:https://www.cnblogs.com/redfox241/p/1474685.html
Copyright © 2011-2022 走看看