




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、一、基于自己創建表的操作1:創建一張學生表 student,擁有stuid,stuname,sex三個字段,其中stuid 為主鍵。create table student(stuid int primary key,stuname VARCHAR(20),sex VARCHAR(20)2 :為該表增加一個新列score。alter table student add(score varchar(10);3 :修改該表score 列名為stuscore。alter table student rename column score to stuscoree;4 :為 student 表插入 5
2、 條記錄。insert into student values。,'張三豐','男',80);insert into student values(2,' 阿悄 ','女',70);insert into student values(3,'陳龍','男',90);insert into student values(4,'章子怡','女',50);insert into student values(5,'張衛健','男',60);5
3、 :查詢 student 表中的全部數據,其中列名為中文。selectSTUIDa鮮號,STUNAMEa姓名,SEXas生另fj ,STUSCOREEas數 fromstudent;6 :查詢學生姓名和分數,并是查詢結果按照學生成績降序排列。select STUNAME,STUSCOREE from student order by STUSCOREE desc;7 :修改所有性別為“男 ”的學生信息為性別為“ male。”update student set SEX='male' where SEX=?';8:刪除所有記錄。delete from student;9
4、:刪除student 表。drop table student;二、基于emp 表的操作1:創建一張新表empl,和emp表結構和記錄完全一樣。create table emp1 as select*from ;基于 emp1 表的操作:1 :選擇部門30 中的雇員。select*from emp1 where DEPTNO=30 and JOB='CLERK'2:列出所有辦事員(CLERK的姓名、編號和部門。select ENAME,EMPNO,DEPTNO from emp1 where JOB='CLERK'3 :找出傭金高(comm )于薪金的雇員。se
5、lect*from emp1 where COMM> SAL and JOB='CLERK'4 :找出傭金高于薪金60%的雇員。select*from emp1 where COMM*> SAL and JOB='CLERK'5 :找出部門10 中所有經理和部門 20 中所有辦事員的詳細資料。select*from emp1 where DEPTNO=10 and JOB='MANAGER' union select*from emp1 whereJOB='SALESMAN'6 :找出部門 10 中所有經理和部門 20
6、 中所有辦事員以及既不是經理又不是辦事員但其薪金大于或等于 2000 的所有雇員的詳細資料。select*from emp1 where DEPTNO=10 and JOB='MANAGER' union select*from emp1 whereJOB='SALESMAN' union select*from emp1 where JOBin('CLERK') and SAL>=2000;7找出收取傭金的雇員的不同工作。select distinct JOB from emp1 where job='CLERK'8 :找
7、出不收取傭金或收取傭金低于 100 的雇員。select *from emp1 where COMM is null or nvl(COMM,0)<100;9:按照部門編號顯示所有雇員信息。select *from emp1 order by DEPTNO;作業要求:將SQL語句復制粘貼在相對應的題目下面。1 :找出各月最后一天受雇的所有雇員select deptno,ename from emp where hiredate =last_day(hiredate);2 :找出早于12 年之前受雇的雇員selectENAME,months_between(sysdate,HIREDATE
8、)/12麻fromempwhereJOB='CLERK'and (months_between(sysdate,HIREDATE)/12)>12;3:顯示只有首字母大寫的所有雇員的姓名select UPPER( SUBSTR(ename,1,1)|LOWER(SUBSTR(ename,2,LENGTH(ename)-1) FROMemp where JOB='CLERK'4 :顯示正好為 15 個字符的雇員姓名select deptno,ename from emp where length(ename)=15 and JOB='CLERK'
9、;5:顯示不帶有的雇員姓名select ename from emp where ename not like '%R%'and JOB='CLERK'6 :顯示所有雇員的姓名的前 3 個字符select substr(ename,1,3) from emp where JOB='CLERK'7:顯示所有雇員的姓名,用替換所有的'Aselect replace(ename,'A','a') from emp;8 :顯示所有雇員的姓名以及滿10 年服務年限的日期select ename,hiredate,ad
10、d_months(hiredate,10*12) from emp;9:顯示雇員的詳細資料,按姓名排序select * from emp order by ename;10 :顯示雇員姓名,根據其服務年限,將最老的雇員排在最前面selectempno,ename,job,mgr,hiredate,sal,comm,deptno,(sysdate- hiredate)/365from emp order by (sysdate-hiredate)/365 desc;11 :顯示所有雇員的姓名、工作和薪金,按工作內的工作的降序順序排序,而工作按薪金排序select ename,job,sal fr
11、om emp order by job desc,sal asc;12 :顯示所有雇員的姓名和加入公司的年份和月份,按雇員受雇日所在月排序,并將最早年份的項目排在最前面select ename,to_char(hiredate,'YYYY') year1,to_char(hiredate,'MON') month1 fromemp order by year1 asc,month1;13 :顯示在一個月為 30 天的情況下所有雇員的日薪金,忽略小數select round(sal/30,0) as daypay from emp;14 :找出在(任何年份的) 2
12、 月份受雇的所有雇員select * from emp where hiredate like '%-2 月 %'15 :對于每個雇員,顯示其加入公司的天數select round(sysdate-hiredate) from emp;16:顯示姓名字段的任何位置,包含闔所有雇員的姓名select ename from emp where ename like '%A%'17 :以年、月和日顯示所有雇員的服務年限selectename,to_number(to_char(sysdate,'YYYY')-to_number(to_char(hire
13、date,'YYYY')-1,to_number(to_char(sysdate,'mm')- to_number(to_char(hiredate,'mm')+10,to_number(to_char(sysdate,'dd')-to_number(to_char(hiredate,'dd')+30fromemp;18:列出至少有一個雇員的所有部門select deptno from emp group by deptno having count(deptno)>0;19:列出薪金比“SMITH;的所有雇
14、員SELECTename,sal,deptnoFROMempWHEREsal>(SELECTsalFROMempWHEREena me='SMITH');20:列出所有雇員的姓名及其部門名select ENAME,DEPTNO from emp where JOB='CLERK'21 :列出所有入職日期早于其直接上級的所有雇員SELECT as 職工 , as 經理 FROM emp e left join emp m on = where <22:列出各種類別的最低薪金,并使薪金大于1500select job, min(sal) from emp
15、 group by job having min(sal)>1500;23:列出薪金高于公司平均水平的所有雇員select ename, deptno from emp where sal>(select avg(sal) from emp);24:列出與“SCOT1事相同工作的所有雇員selectdeptno,enamefromempwherejob=(selectjobfromempwhereename='SCOT T');25:列出薪金高于在部門30工作的所有雇員的薪金SELECT ename,sal from emp where sal >all(se
16、lect sal from emp wheredeptno=30);26:列出薪金高于在部門30工作的最高的薪金SELECTename,salfromempwheresal>all(selectmax(sal)fromempwheredeptno=3 0);27:列出每個部門雇員的數量select deptno,count(*) from emp group by deptno;28:列出所有雇員的名稱,部門名稱和薪金select ENAME,DEPTNO,SAL from emp where JOB='CLERK'29:列出從事同一種工作但不屬于同一部門的這些員工sel
17、ect job,deptno from emp group by job,deptno;30:列出個類別工作的最低工資select job,min(sal) from emp group by job;31 :列出各個部門的經理的最低薪金select DEPTNO,min(sal) from emp where job='MANAGER' group by DEPTNO;32:列出按計算的字段排序的所有雇員的年薪select ename,(sal+nvl(comm,0)*12 as yearpay from emp order by yearpay desc;33列出所有CLE
18、RK勺姓名及其部門名稱select ENAME,DEPTNO from ep where JOB='CLERK'34:列出薪金水平處于前四位的雇員select sal,ename from emp order by sal desc;35:求出所有員工入職了多少年零多少月零多少天selectempno,ename,to_char(floor(to_number(sysdate- hiredate)/365)|'years'|to_char(ceil(months_between(sysdate,hiredate)- (floor(to_number(sysdat
19、e-hiredate)/365)*12)|' months ' from emp;作業要求:將SQL語句復制粘貼在相對應的題目下面。1 :找出各月最后一天受雇的所有雇員select * from emp where hiredate=last_day(hiredate);2 :找出早于12 年之前受雇的雇員select*fromempwhereto_number(to_char(sysdate,'yyyy')- to_number(to_char(hiredate,'yyyy')>12;3 :顯示只有首字母大寫的所有雇員的姓 名SELECT
20、 initcap(ename) FROM emp;SELECT ename from emp where ename=initcap(ename);4 :顯示正好為15 個字符的雇員姓名select ENAME from emp where length(ENAME)=15;5:顯示不帶有的雇員姓名select ENAME from emp where ENAME not like '%R%'6 :顯示所有雇員的姓名的前3 個字符select substr(ENAME,0,3) from emp;7:顯示所有雇員的姓名,用替換所有的'Aselect replace(EN
21、AME,'A','a') from emp;8 :顯示所有雇員的姓名以及滿10 年服務年限的日期select ename, add_months(hiredate,120) from emp;9:顯示雇員的詳細資料,按姓名排序select * from emp order by ename;10 :顯示雇員姓名,根據其服務年限,將最老的雇員排在最前面select ename from emp order by hiredate;11 :顯示所有雇員的姓名、工作和薪金,按工作內的工作的降序順序排序,而工作按薪金排序select ename,job,sal from
22、 emp order by job desc, sal desc;12 :顯示所有雇員的姓名和加入公司的年份和月份,按雇員受雇日所在月排序,并將最早年份的項目排在最前面selectename,to_char(hiredate,'yyyy-mm')as"力口入年月"fromemporderbyto_char(hiredate,'mm') asc, to_char(hiredate,'yyyy') asc;13 :顯示在一個月為30 天的情況下所有雇員的日薪金,忽略小數select round(sal/30,0) from emp
23、;14 :找出在(任何年份的)2 月份受雇的所有雇員select * from emp where to_char(hiredate, 'mm')='02'15 :對于每個雇員,顯示其加入公司的天數select ename,round(sysdate-hiredate,0) "加入公司天數" from emp;16 :顯示姓名字段的任何位置,包含闔所有雇員的姓名select ename from emp where ename like '%A%'17 :以年、月和日顯示所有雇員的服務年限selectename,hiredat
24、e,trunc(months_between(sysdate,hiredate)/12) 年,trunc(mod(months_between(sysdate,hiredate),12)月,trunc(sysdate- add_months(hiredate,months_between(sysdate,hiredate) 日 fromemp;18:列出至少有一個雇員的所有部門select deptno,count(0) from emp group by deptno having count(0)>=119:列出薪金比“SMITH;的所有雇員select ename from emp
25、 where sal >(select sal from emp where ename = 'SMITH');select e2.* from emp e1, emp e2 where ='SMITH'and >20:列出所有雇員的姓名及其部門名select , from emp e,dept d where =;select , from emp e join dept d on =;21 :列出所有入職日期早于其直接上級的所有雇員select * from emp e1 where hiredate<(select hiredate fr
26、om emp e2 where =;22:列出各種類別的最低薪金,并使薪金大于1500select job,min(sal) from emp group by job having min(sal)>1500;23:列出薪金高于公司平均水平的所有雇員select * from emp where sal>(select avg(sal) from emp);24:列出與“SCO成事相同工作的所有雇員select * from emp where job=(select job from emp where ename='SCOTT');25:列出薪金高于在部門30
27、 工作的所有雇員的薪金select ename, sal from emp where sal>(select max(sal) from emp where deptno=30);select ename, sal from emp where sal>all(select sal from emp where deptno=30);26:列出薪金高于在部門30工作的最高的薪金select ename, sal from emp where sal>(select max(sal) from emp wheredeptno=30);27:列出每個部門雇員的數量select d.*, (select count(deptno) from emp e where = "雇員人數" from deptd;2
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025新入職工安全培訓考試試題附參考答案(輕巧奪冠)
- 2025廠里安全培訓考試試題5A
- 2025公司、項目部、各個班組安全培訓考試試題(考題)
- 知到智慧樹網課:病理生理學(南方醫大)章節測試滿分答案
- 2025跨境電商購銷合同范本
- 2025租房合同標準范本
- 2025移動應用版本軟件授權合同樣書
- 2025精簡版房屋裝修合同協議
- 2025購方信貸合同示范文本
- 2025辦公室租賃合同范例
- 2023-2024學年滬科版(2019)高中信息技術必修一第三單元項目六《解決溫標轉換問題-認識程序和程序設計語言》教學設計
- 《豬的傳染病》課件
- 非煤礦山安全生產作業指導書
- 《新媒體營銷》課件-項目一 新媒體營銷認知
- 醫學倫理學的倫理原則
- 2025年春新人教PEP版英語三年級下冊課件 Revision Going to a school fair-第2課時
- 《健康進課堂》2024年幼兒園家長助教醫療版
- 《汽車涂裝》2024-2025學年第一學期工學一體化課程教學進度計劃表
- 小學生涯回顧分享模板
- 機關財務課件
- 2025年冀教版七年級英語下冊教學工作計劃
評論
0/150
提交評論