1樓:匿名使用者
select id, name, 'name'+ltrim(str(row_number() over(partition by id order by name))) as field1
into #c from tab
select id,name1,name2,name3,name4,name5
from #c a pivot (max(name)for field1 in (name1,name2,name3,name4,name5)) as pvt
2樓:
declare @sql varchar(8000)set @sql = 'select id'
select @sql = @sql+', max(case [id] when '''+cast(id as varchar)+''' then name else 0 end ) as [name'+cast(id as varchar)+']'
from (select distinct id ,name from tab ) as a
set @sql = @sql +' from testid group by id'
--select @sql
exec (@sql)
3樓:匿名使用者
可以考慮
select id group_concat(name) as name from tab group by id;
這樣就可以取出3條記錄
然後把name分割之後顯示。
4樓:匿名使用者
你的name是固定到name5嗎?
關於SQL的問題,請高手指點
select 姓名 count 姓名 as countnum into t1 from 學生資訊 group by 姓名 select from 學生資訊 where 姓名 in select 姓名 from t1 where countnum 1 這樣子寫應該可以,你也可在將兩句放到一起,但那樣子...
關於SQL的連線查詢,關於SQL的連線查詢
使用union all試下 select from tb book where eliteid 3 order by booktime desc union all select from tb book where eliteid 3 order by topnumber desc,booktim...
SQL查詢的問題,PL SQL查詢的問題。
select tt.from select t.row number over partition by t.c1 order by t.c2 desc rn from aaa t tt where tt.rn 1 分析函式 的作用是按c1進行分組,並且對每個組進行排序 select t.row n...