zoukankan      html  css  js  c++  java
  • 数据库行列转换

    数据表:

    index       content       num
    1           hello         1
    1           mr            2
    1           king          3
    2           I             1
    2           am            2
    2           best          3
    2           the           4


    写出sql语句,得到一下查询结果:

    查询结果:

    index       content      
    1           hello mr king
    2           I am the best


    alter function dbo.fun_content
    (@id int)
    RETURNS VARCHAR(32) AS
    begin
    declare @str varchar(500)
    set @str = ''
    select @str = @str + ' ' + content from test2 where id=@id order by num
    return @str
    end
    go

    select id,dbo.fun_content(t.id) from test2 t group by id

  • 相关阅读:
    HDU 1017—A Mathematical Curiosity
    N !
    L
    J
    Danganronpa
    A water problem
    hdu 5461 Largest Point
    India and China Origins hdu 5652 (BFS+二分)
    D (多校训练三) poj1919 (二分)
    Discovering Gold lightoj 1030 (dp+期望)
  • 原文地址:https://www.cnblogs.com/xp/p/933224.html
Copyright © 2011-2022 走看看