前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >oraclesql面试题sql笔试题_oracle高级面试题

oraclesql面试题sql笔试题_oracle高级面试题

作者头像
Java架构师必看
发布2022-09-26 21:32:50
4150
发布2022-09-26 21:32:50
举报
文章被收录于专栏:Java架构师必看

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说oraclesql面试题sql笔试题_oracle高级面试题,希望能够帮助大家进步!!!

1删除重复记录

delete from t where t.rowid not in ( select max(rowid) from t group by name); 2根据2表的关联列,更新1个表的多个字段

update t

set t.address = ( select e.address from e,t where t.name = e.name),

t.phone = ( select e.phone from e,t where t.name = e.name); 3选择一段范围内的数据

select * from t where rownum <= 5

minus

select * from t where rownum < 3;

或者

select * from ( select rownum as rn,t.* from t ) s

where s.rn between 3 and 5; 查询工资最高的几个人

select * from (select * from emp order by salary desc) where rownum<=3;

几个行转列,列转行的测试

SQL> select * from t;

ID NAME


1 a

2 b

3 c

4 d

1 e

1 f

1 g

2 h

2 i

2 j

已选择10行。

select id ,wm_concat(name) from t group by id;

11 a,e,f,g

22b,h,j,i

33c

44d

select * from test_tb_grade;

11 bai语文 78

22bai数学89

33bai英语90

44xiao语文67

55xiao数学98

66xiao英语56

下面是使用decode和case when的转换

select user_name,

sum(decode(course,'语文',score,null)),sum(decode(course,'数学',score,null)),sum(decode(course,'英语',score,null))

from test_tb_grade group by user_name;

select user_name,

sum(case when course = '语文' then

score

else null end ),

sum(case when course = '数学' then

score

else null end),

sum(case when course = '英语' then

score

else null end)

from test_tb_grade group by user_name;

对应的查询结果如下:

1bai 788990

2xiao 679856

列转行,主要是使用了union

select * from test_tb_grade2;

11 bai67 7890

21xiao8988 96

select user_name, cn_score

from test_tb_grade2

union

select user_name, math_score

from test_tb_grade2

union

select user_name, en_score from test_tb_grade2;

1bai 67

2bai78

3bai90

4xiao 88

5xiao 89

6xiao 96

参考

http://blog.csdn.net/zhoubo200/article/details/5338107

http://www.2cto.com/database/201108/100792.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-09-242,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档