关于Oracle面试官喜欢问的那些语句

1、聚合函数,avg求平均值:

select avg(字段名) from 表名 where 条件;

select avg(all 字段名) from 表名 where 条件; #同上

select avg(distinct 字段名) from 表名 where 条件;  #distinct只对不同的值求平均值

2、聚合函数,sum求和:

select sum(字段名) from 表名 where 条件;

3、聚合函数,max最大值:

select max(字段名) from 表名 where 条件;

4、聚合函数,min最小值:

select min(字段名) from 表名 where 条件;

5、聚合函数,count求行数:

select count(字段名) from 表名 where 条件;

6、查询前10条数据:

select t.列名,t.* from 表名 t where  rownum<=10 order by t.列名 asc; #order by asc升序排序

select t.列名,t.* from 表名 t where  rownum<=10 order by t.列名 desc; #order by desc降序排序

还有一种写法,先按照升序排序,再查询出前10列(效率比上一种低,有说法这种排序比较准确,个人实际执行后查询结果是一样的):

select * from (select t.列名 from 表名 t order by t.列名 asc)where  rownum<=10 ;

7、左连接,左表都展示,右表仅展示可以匹配左表的列,其余列显示空:

select * from 表名A a left join 表名B b on a.列名 = b.列名;

8、右连接,右表都展示,左表仅展示可以匹配右表的列,其余列显示空:

select * from 表名A a right join 表名B b on a.列名 = b.列名;

9、内连接,仅展示左表、右表可以匹配的列:

select * from 表名A a inner join 表名B b on a.列名 = b.列名;

10、全连接,展示所有的行:

select * from 表名A a full outer join 表名B b on a.列名 = b.列名;

11、dual表查日期:

select sysdate from dual;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值