当前位置:Gxlcms > 数据库问题 > Oracle基础查询

Oracle基础查询

时间:2021-07-01 10:21:17 帮助过:11人阅读

select * from teacher
--女性老师编号、姓名
select tno,tname,gendar from teacher where gendar=‘女‘
--姓韩的女性老师编号、姓名、身份证号
select tno,tname,tid from teacher where gendar=‘女‘ and tname like ‘韩%‘
--薪水在[10000,20000)之间老师列表
select sal,tname from teacher where sal between 10000 and 20000
--岗位为讲师或者研发,按照薪水降序排序
select tname,sal,job from teacher where job in(‘讲师‘,‘研发‘)
order by sal desc
--部门所有数据的INSERT语句
select * from dept
--oracle使用|| 来连接字符串
insert into dept values(40,‘人力部‘,‘北京海淀‘)
--怎么查询
select ‘insert into dept values(‘||deptno||‘,‘‘‘||dname||‘‘‘‘||‘,‘‘‘||loc||‘‘‘);‘
from dept;

 

select * from teacher
--招生部门所有男老师姓名
--使用子查询
select tname,gendar,deptno
from teacher
where deptno=(select deptno from dept where dname=‘招生部‘)
and gendar=‘男‘
--使用内连接 01
select tname,gendar,d.deptno,dname
from teacher t,dept d
where t.deptno=d.deptno
and gendar=‘男‘ and dname=‘招生部‘

--使用内连接 02
select tname,gendar,d.deptno,dname
from teacher t inner join dept d
on t.deptno=d.deptno
where gendar=‘男‘ and dname=‘招生部‘

--所有老师姓名、部门
select tname,dname
from teacher t,dept d
where t.deptno=d.deptno

--所有老师的姓名以及其导师的姓名 自连接
select t1.tname,t2.tname as 导师姓名 from teacher t1,teacher t2
where t2.tno=t1.mgrno


--所有老师的姓名、部门、导师
select t.tname as 老师姓名,t1.tname as 导师姓名,d.dname as 部门
from teacher t left join teacher t1
on t.mgrno=t1.tno
left join dept d
on t.deptno=d.deptno

--列出所有姓名和出生日期
select tname,birthdate from teacher

 

Oracle基础查询

标签:

人气教程排行