zoukankan      html  css  js  c++  java
  • 求sql查询语句(转换数据表由纵向转换成横向)

    我的表结构:   
      ID(主键)     studentNo   courseNo   score   
      
    1                     01                 2001         99   
      
    2                     01                 2002         98   
      
    3                     01                 2003         97   
      
    4                     02                 2001         95   
      
    5                     02                 2002         94   
      
    6                     02                 2003         93   
    -----------------------------------------------
      查询结果   
      studentNo     
    2001           2002           2003   
      
    01                       99               98               97   
      
    02                       95               94               93 
    declare   @s   varchar(
    8000)   
      
    set   @s=@s+',['+cast(courseNo   as   varchar)+']=sum(case   courseNo   when   '''+cast(courseNo   as   varchar)+'''   then   score   end)'   
      from   表   
      group   by   courseNo   
      exec(
    'select   studentNo'+@s+'   from   表   group   by   studentNo')
    转载CSDN:http://topic.csdn.net/t/20040611/09/3082327.html
  • 相关阅读:
    ExceptionExtensions
    implicit operator
    javascript Demo
    KO Demo
    Model Binding
    Await Async Task
    STL查找序列中处于某一大小范围内的元素个数
    2017头条笔试题:二维点集中找出右上角没有点的点并按x坐标从小到大打印坐标
    VS2017新建windows控制台程序打印中文乱码问题
    【详解】Linux的文件描述符fd与文件指针FILE*互相转换
  • 原文地址:https://www.cnblogs.com/zpq521/p/1240908.html
Copyright © 2011-2022 走看看