如果对如下SQL有疑问,可以留言。
--纵表变横表BEGIN
select a as 'a',
max(case b when 'name' then c else 0 end ) name,
max(case b when 'sex' then c else 0 end ) sex,
max(case b when 'age' then c else 0 end ) age,
max(case b when 'plan_code' then c else 0 end ) plan_code from a group by a;
--纵表变横表END
如下是上面例子的准备SQL
create table a
(a varchar(2),
b varchar(100),
c varchar(100));
insert into a values('1', 'name', 'xiaoming');
insert into a values('1', 'sex', 'm');
insert into a values('1', 'age', '10');
insert into a values('1', 'plan_code', '966');
insert into a values('2', 'name', 'xiaohong');
insert into a values('2', 'sex', 'f');
insert into a values('2', 'age', '9');
insert into a values('2', 'plan_code', '966');
交流Q群:90807359