---行转列
create table tb( name varchar(10), subject varchar(10), result int); insert into tb values ('张三','语文',74); insert into tb values ('张三','数学',83); insert into tb values ('李四','语文',80); insert into tb values ('李四','数学',86); select * from tb; -----输出格式如下----
姓名 语文 数学 张三 74 83 李四 80 86
select name, sum(case when subject='语文' then result end )as 语文, sum(case when subject='数学' then result end) as 数学 from tb group by name ;
---merge into语句
MERGE INTO USER_TEST T1
USING (SELECT '1001' AS ID,'王睿' AS NAME FROM dual) T2
ON ( T1.ID=T2.ID)
WHEN MATCHED THEN
UPDATE SET T1.NAME = T2.NAME
WHEN NOT MATCHED THEN
INSERT (NAME) VALUES(T2.NAME);
commit;