練習基於Oracle數據庫中SCOTT用戶下的emp表
- 查詢scott用戶下的全部表
select * from tabs;
- 查詢僱員表中的所有信息
select * from emp;
- 查詢僱員編號,姓名,工做,工資。
select empno,ename,job,sal from emp;
- 查詢僱員編號,姓名,工做,工資,列表標題需中文顯示。
SELECT empno "僱員編號",ename "僱員姓名" ,job "工做",sal "工資" from emp;
- 查詢僱員工做種類。
select distinct job from emp;
- 查詢全部僱員編號,姓名,工做.按如下格式顯示:編號:7369-姓名:SMITH-工做:CLERK (返回一個列)
select '編號:' || empno || '-姓名:' || ename || '-工做:' || job as 詳情 from emp;
- 查詢僱員編號,姓名,工做,年薪
select empno,ename,job,(sal + nvl(comm,0))*12 YearlySalary from emp;
- 查詢工資大於1500的僱員全部信息
select * from emp where sal >1500;
- 查詢能夠獲得獎金的僱員的名字與獎金
select ename,comm from emp where NVL(comm,0)>0;
select ename,comm from emp where DECODE(comm,null,0,comm) > 0;
- 查詢工資大於1500或能夠獲得獎金的僱員
select ename from emp where sal > 1500 or nvl(comm,0) > 0;
select ename from emp where sal > 1500 or DECODE(comm,null,0,comm) > 0;
- 查詢工資大於1500而且能夠領取獎金的僱員
select ename from emp where sal > 1500 and nvl(comm,0) > 0;
select ename from emp where sal > 1500 and DECODE(comm,null,0,comm) > 0;
- 查詢工資不大於1500或者不能夠領取獎金的僱員
select ename from emp where sal <= 1500 or nvl(comm,0) = 0;
- 查詢工資在1500到3000的全部僱員信息
select * from emp where sal >=1500 and sal <= 3000;
- 查詢系統當前時間
select sysdate from dual;
- 查詢在1981年僱用的員工信息
select * from emp where hiredate like '%81%';
select * from emp where to_char(hiredate,'YYYY') = '1981';
select * from emp where hiredate <= to_date('1981-12-31','YYYY-mm-dd') and hiredate >= to_date('1981-01-01','YYYY-mm-dd');
select * from emp where hiredate between to_date('1981-01-01','YYYY-mm-dd') and to_date('1981-12-31','YYYY-mm-dd');
- 查詢僱員姓名中第三個字母爲」A」的僱員信息
select * from emp where ename like '__A%';
- 查詢僱員編號爲7369的僱員信息
select * from emp where empno = '7369';
- 查詢僱員編號不爲7369的僱員信息
select * from emp where empno != '7369';
select * from emp where empno <> '7369';
- 查詢編號是7369,7900的僱員信息
select * from emp where empno in (7369,7900);
- 查詢編號不是7369,7900的僱員信息
select * from emp where empno not in (7369,7900);
- 查詢僱員信息,按工資由低到高排序
select * from emp order by sal;
select * from emp order by sal asc;
- 查詢僱員信息,按工資由高到低排序
select * from emp order by sal desc;
- 請查詢沒有領導的員工名和職位
select ename,job from emp where mgr is null;
- 查詢有領導的員工名和職位
select ename,job from emp where mgr is not null;
- 查詢全部員工名、職位以及領導名
select e1.ename,e1.job,e2.ename from emp e1,emp e2 where e1.mgr = e2.empno(+);
- 查詢部門30中的全部員工信息
select * from emp where deptno = 30;
- 列出全部辦事員(CLERK)的姓名,編號和部門編號(按部門編號升序排列)
select ename,empno,deptno from emp where job = 'CLERK' order by deptno;
- 找出佣金高於薪金的員工
select * from emp where nvl(comm,0) > sal;
- 找出佣金低於薪金的40%的員工信息
select * from emp where nvl(comm,0) < sal*0.4;