oracle学习新手,求几条sql的标准答案对照~~~

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle学习新手,求几条sql的标准答案对照~~~相关的知识,希望对你有一定的参考价值。

数据中的表格如下:
Employee(EID, Fname, Lname, Address, DOB, Gender, Salary, Bonus, DID)
Department(DID, Name, Mgr_EID, Mgr_Start_Date)
Project(PID, Name, DID)
Work_On(EID, PID, Hours)
PS:DID:Department的ID,DOB:生日。。
SQL 问题:(1)寻找在department中的research department中年龄第二小的。
(2)找出employee里面的名字包含字母"Y"的,并用desending的顺序排列。
(3)找到所有比平均年龄大的employee,列出名字.
(4) 找出每个department所承担的project的数量,并列出department的名字
(5)找出只承担1个project的employee,并列出名字
(6)找出承担大于1个project的employee,列出名字
(7)找出每个employee所承担的project的数量,每个employee的名字要列出
(8)找出男(male)employee和女(female)employee个承担的project的数量
(9)每一个project的有几个employee在做, 要列出project的名字
各位大侠帮忙看下。。。感激不尽~~~,先给100,正确回答了在附加100~~

1、
select EID,Fname from
(select rownum id,E.EID,E.Fname from Employee E,Department D where E.DID=D.DID and D.Name='research' order by DOB desc)
where id=2;
2、
select EID,Fname from Employee where Fname like '%Y%' order by Fname desc;
3、
select Fname from Employee where DOB<(select agv(DOB) from Employee);
4、
select D.DID,D.Name,count(P.PID) from Department D,Project P where D.DID=P.DID group by D.DID,D.Name;
5、
select Fname from
(select E.EID,E.Fname Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname having count(W.PID)=1);
6、
select Fname from
(select E.EID,E.Fname Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname having count(W.PID)>=1);
7、
select Fname,project数量 from
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname);
8、
select A.EID,A.Fname,A.project数量 maleproject数量,B.project数量 femaleproject数量 from
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID and E.Gender='male' group by E.EID,E.Fname)A,
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID and E.Gender='female' group by E.EID,E.Fname)B;
where A.EID=B.EID;
9、
select P.Name,count(W.EID) Work_On W,Project P where W.PID=P.PID group by P.Name;

---
以上,希望对你有所帮助。
参考技术A select Fname from (select top (2) Fname from Employee,Department where Department.name='research '
order by DOB desc) where DOB>ANY(DOB)
SELECT * FROM Employee WHERE Fname like '%Y%'
select Fname from Employee where (sysdate-DOB)>(select avg(sysdate-DOB) from Employee)
select Department.name,count(PID) from Department,Project group by Department.DID
select Fname from Employee where EID in (select EID from Project,Work_On where EID is unique)
select Fname from Employee where Fname not in (select Fname from Employee where EID in (select EID from Project,Work_On where EID is unique))
select Fname,count(PID) from Employee,Project,Work_On
select count(PID),count(select PID from Employee,Project,Work_On)-count(PID) from Employee,Project,Work_On where Gender='male'
select Project.name,count(EID) from Employee,Project,Work_On group by Project.name

oracle开展分组后,取出每组的前几条数据

参考技术A oracle进行分组后,取出每组的前几条数据SELECT *FROM (SELECT 分组的字段名,ROW_NUMBER() OVER(PARTITION BY 分组的字段名 ORDER BY 排序的字段名) AS RNFROM 表名)WHERE RN <= 10�0�2本回答被提问者采纳

以上是关于oracle学习新手,求几条sql的标准答案对照~~~的主要内容,如果未能解决你的问题,请参考以下文章

初学C++求几个适合新手的OJ刷题网站

oracle取前几条数据语句

提高性能的 Oracle SQL 新手

用SQL如何查询第几条到第几条之间的数据?想不出来呢,网上的答案都不行的

oracle中dual表中有几条记录?

Oracle 11g 中的限制子句