表結構和內容:
insert into test(val1,val2) values('name','wd');
insert into test(val1,val2) values('email','[email protected]');
insert into test(val1,val2) values('age','30');
sql語句:
declare @s varchar(8000)
set @s = 'select ';
select @s = @s + val1 +' = max(case when val1 = ''' + val1 + ''' then val2 end), '
from test
set @s = left(@s, len(@s) - 1)
set @s = @s + ' from test'
exec(@s)
MySQL行轉列sql語句
create table test tb grade id int 10 notnull auto increment user name varchar 20 default null course varchar 20 default null score float default 0 pri...
mysql 查詢行轉列 SQL語句實現行轉列查詢
表sales 查詢結果如下 1 建表 create table dbo sales id int identity 1,1 not null,year int null,jidu int null,jine int null,primary key clustered id asc with pad...
典型的行轉列的SQL語句
以oracle資料庫為例,將tab表中的tname欄位轉成以逗號分隔的字串 sql 1 select substr max sys connect by path tname,2 from select b.tname,b.t1,lead b.t1,1 over order by b.t1 t2 f...