• 数据库行列转换


    数据表:

    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

  • 相关阅读:
    socket tools
    AcWing 1172 祖孙询问
    AcWing 1170 排队布局
    AcWing 393 雇佣收银员
    AcWing 362. 区间
    基于最短路的差分约束模型
    AcWing 1169 分糖果
    树上差分
    AcWing 352 . 闇の連鎖
    AcWing 1171. 距离
  • 原文地址:https://www.cnblogs.com/xp/p/933224.html
Copyright © 2020-2023  润新知