Oracle簡單查詢執行個體

來源:互聯網
上載者:User

標籤:xxx   manager   code   red   comm   有獎   簡單   esc   詳細   

--查詢不重複的職位select distinct job from emp;--查詢年薪,起別名,別名不要用單引號括起來select sal*12 as nianxin from emp sal;--以這樣的形式顯示具體資料:僱員編號是:姓名是:工資為:職位是:!select ‘僱員編號是:‘||empno,‘姓名是:‘||ename,‘工資是:‘||sal,‘職位是:‘||job||‘!‘ from emp;--查詢不是職位不是“CLERK”的員工資訊(至少用2種方式查詢)select * from emp where job != ‘CLERK‘;select * from emp where job not like ‘%CLERK%‘;--查詢下員工姓名中有O和T的select * from emp where ename like ‘%O%‘ and ename like ‘%T%‘;--將員工工資按照由高到低的順序排列select sal from emp order by sal desc;--查詢顯示工資大於各個部門工資的平均值的員工的年齡select empno,a.deptno,a.sal,b.deptno,b.gsal,round((sysdate - hiredate) / 365, 0) --年齡from emp a,(select deptno,round(avg(sal),0)as gsal from emp group by deptno) b --基表和視圖表where a.deptno=b.deptno --主鍵串連基表和視圖and a.sal>b.gsal; --工資大於各部門平均工資--查詢各個部門工資範圍,按照1000~2000,2000~3000.。。。這樣的格式顯示人數--------------------------沒看懂意思--要求查詢出工資比SMITH工資要高的全部僱員資訊select * from emp where sal>(select sal from emp where ename=‘SMITH‘);--要求查詢出高於公司平均工資的全部僱員資訊select * from emp where sal>(select avg(sal) from emp);--查詢出每個部門的編號、名稱、位置、部門人數、平均工資select deptno,avg(sal) from emp group by deptno;--統計各個部門的人數*/select deptno,count (*) from emp group by deptno;select * from emp;--1  選擇部門30中的所有員工。select ename from emp where deptno = ‘30‘;--2  列出所有辦事員(CLERK)的姓名,僱員編號和部門編號。select ename,empno,deptno from emp where job=‘CLERK‘;--3  找出獎金高於薪金的員工。select ename from emp where comm>sal;--4  找出獎金高於薪金60%的員工。select ename from emp where comm>(sal*0.6);--5  找出部門10中所有經理(MANAGER)select * from emp where deptno = ‘10‘ and job = ‘MANAGER‘;--6  找出部門10中所有經理(MANAGER),以及所有部門中即不是經理又不是辦事員但薪金大於或等於2000的所有員工的詳細資料。select * from emp where (deptno=10 and job = ‘MANAGER‘) or (job not in(‘MANAGE‘,‘CLERK‘) and sal>=2000)select * from emp;--7  找出有獎金的員工的不同工作。select distinct job from emp where comm>0;--8  找出沒有獎金或獎金低於100的員工。select * from emp where (comm<100 or comm is not null);--9  找出每個月倒數第3天受雇的所有員工。select * from emp where hiredate=(last_day(hiredate)-2);--10  找出早於30年前受雇的員工。select * from emp where add_months(sysdate,-30*12)>=hiredate; --add_months(xxxx,+or-) 目前時間+或者減月份--11  以首字母大寫的方式顯示所有員工的姓名。select initcap(ename) from emp;--12  顯示正好為5個字元的員工的姓名。select ename from emp where length(ename)=5;--13  顯示不帶有‘R‘的員工的姓名。select ename from emp where ename not like ‘%R%‘;--14  顯示所有員工姓名的前三個字元。select substr(ename,3) from emp;--15  顯示所有員工的姓名,用‘L‘代替所有‘A‘select replace (ename,‘L‘,‘A‘) from emp;--16  顯示滿30年服務年限的員工的姓名和受雇日期。select months_between(sysdate,hiredate)/12 from emp;select ename,hiredate from emp where months_between(sysdate,hiredate)/12 >=30 ;--17  顯示員工的詳細資料,按姓名排序。select * from emp order by ename desc;--18  顯示員工的姓名和受雇日期,根據其服務年限,將最老的員工排在最前面。select ename,hiredate from emp order by hiredate;--19  顯示所有員工的姓名、工作和薪金,按工作的降序排序,若工作相同則按薪金排序。select ename,job,sal from emp order by job desc,sal ;--20  顯示所有員工的姓名、加入公司的年份和月份,按受雇日期所在月排序,若月份相同則將最早年份的員工排在最前面。select ename,to_char(hiredate,‘yyyy‘)年份,to_char(hiredate,‘mm‘) 月份 from emp order by 月份,年份;----------------------------------21  顯示在一個月為30天的情況所有員工的日薪金,忽略餘數。select trunc(sal/30) from emp;--22  找出在(任何年份的)2月受聘的所有員工。select * from emp where to_char(hiredate,‘mm‘)=2;--23  對於每個員工,顯示其加入公司的天數。select ename,sysdate-hiredate from emp;--24  顯示姓名欄位的任何位置包含‘A‘的所有員工的姓名。select ename from emp where ename like ‘%A%‘;

 

Oracle簡單查詢執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.