SQL语句怎样行转列,要求不用过程比如
table aid  amount
1   40
1   80
2   10
2   20
3   60得到
1  40/80
2  10/20
3  60

解决方案 »

  1.   

    SQL2000嗎?
    --游標
    --函數
    --臨時表
    --固定行要哪個?
      

  2.   

    看来只能用函数了
    我想用一句SQL语句不行啊?
    因为我的行不固定的
    帮忙写一下好么
    谢谢
      

  3.   

    一句sql语句的,我还没想出来!
      

  4.   

    create table cs1(id int,amount int)
    insert into cs1 select 1,40
    union all select 1,80
    union all select 2,10
    union all select 2,20
    union all select 3,60
    CREATE FUNCTION dbo.f_str(@id varchar(100))
    RETURNS varchar(1000)  AS  
    BEGIN declare @s varchar(4000)
    set @s=''
    select  @s=@s+'/'+ltrim(amount) from cs1 where id=@id
    if @s<>''
    set @s=stuff(@s,1,1,'')
    return @s
    END
    select id,dbo.f_str(id) amount from cs1 group by id