hql和sql练习题
SQL与HQL练习题
中的所有员工。
select * from emp where deptno = 30
from Emp e where e.deptno = 30
2. 列出所有办事员(CLERK)的姓名、编号和部门编号。
select t.ename,t.empno,t.deptno from emp t where t.job = ‘CLERK’
select t.ename,t.empno,t.deptno from Emp t where t.job = ‘CLERK’
3. 找出佣金高于薪金的员工。
Select * from emp where comm>sal
From Emp where comm > sal
4. 找出佣金高于薪金的60%的员工。
Select * from emp where comm > (sal*0.6)
From Emp where comm > (sal*0.6)
5. 找出部门10中所有经理(MANAGER)和部门20中所有办事员(CLERK)的详细资料。
select * from emp where (job = ) or (job = );
From Emp where (job = ) or (job = );
6. 找出部门10中所有经理(MANAGER),部门20中所有办事员(CLERK),既不是经理又不是办事员但其薪金大于或等于2000的所有员工的详细资料。
select * from emp where (job = ) or (job = )or(job <> );
select * from Emp where (job = ) or (job = )or(job <> );
7. 找出收取佣金的员工的不同工作。
select distinct t.job from emp t where t.comm >
select distinct t.job from Emp t where t.comm >
8. 找出不收取佣金或收取的佣金低于100的员工。
select * from emp t where t.comm < or t.comm is null
select * from Emp t where t.comm < or t.comm is null
9. 查询所有部门名称和员工姓名,包括没有员工的部门名称也显示。
select d.dname,e.ename from dept d left join emp e on e.deptno = d.deptno;
select d.dname,e.ename from Dept d left join Emp e with e.deptno = d.deptno;
10. 查询工资高于公司平均工资的所有员工信息。
select * from emp where sal > (select avg(sal) from emp);
from Emp t where t.sal in(select avg(e.sal) from Emp e)
11. 查询工资高于部门平均工资的所有员工。
select * from emp t where t.sal >(select avg(e.sal) from emp e where t.deptno = e.deptno)
from Emp t where t.sal >(select avg(e.sal) from Emp e where t.deptno = e.deptno)
12. 查询emp表的第1~3行。
select * from emp t where rownum <=
session.createQuery(from Emp).setFirstResult(0).setMaxResults(3).list()
13. 把员工姓名和工作类型连接在一起,中间用“-”分割显示(concat函数)。
select CONCAT(ENAME||个字符和第4个字符以后的内容显示。
select substr(ENAME,,)||) from emp
select substring(ename,,)||) from Emp
15. 查询员工编号,姓名和所在部门的名称。
select EMPNO,ENAME,DNAME from emp t,dept d where t.deptno = d.deptno
select empno||’’||ename||’’||dname from Emp t,Dept d where t.deptno = d.deptno
16. 查询部门的名称以及该部门的人数,要求没有员工的部门也要显示。
select DNAME,count(e.EMPNO) from dept t left join emp e on t.deptno = e.deptno group by DNAME
select dname,count(e.empno) from Dept t left join Emp e on t.deptno = e.deptno group by dname
Sting = “i”
17. 查询员工姓名及其直接上级的姓名。
select e.ENAME,t.ENAME from emp e,emp t where e.mgr = t.empno
select e.ename||’的上级’||t.ename from Emp e,Emp t where e.mgr = t.empno
18. 查询工资高于平均工资的员工姓名。
select e.ENAME from emp e where e.sal > (select avg(sal) from emp);
select e.ename from Emp e where e.sal >(select avg(t.sal) from Emp t)
19. 查询工资高于本部门平均工资的员工。
select e.ENAME from emp e where e.SAL > (select avg(t.SAL) from emp t where e.DEPTNO = t.DEPTNO);
select e.ename from Emp e where e.sal> (select avg(t.sal) from Emp t where e.deptno = t.deptno)
20. 查询每个部门中拥有最高工资的员工的信息。
select e.ENAME from emp e where e.SAL = (select max(t.SAL) from emp t)
select e.ename from Emp e where e.sal = (select max(t.sal) from Emp t)
21. 统计“JONES”所带领的团队的工资总额。
select sum(e.SAL) from emp e where e.MGR = (select t.MGR from emp t where t.ENAME = 号部门中有而20号部门中没有的工作。
select e.job from emp e where e.deptno = and e.job not in(select t.job from emp t where t.deptno = )
select e.job from Emp e where e.deptno = and e.job not in(select t.job from Emp t where t.deptno = )
23. 记录并集(union)
select * from emp where EMPNO = union select * from emp where EMPNO =
union select * from Emp where EMPNO =
,+年前参加工作的员工。
select * from emp t where t.hiredate <(select sysdate - interval = hiredate
11. 查询每个员工的工作天数。
select sysdate-hiredate as days from emp
天计算员工的日薪金,要求计算结果四舍五入到小数点后2位。
select trunc(t.SAL/,) from emp t
select trunc(t.sal/,) from Emp t
14. 计算每个员工已经工作了多少个月,要求忽略小数部分。
select trunc((sysdate-hiredate)/) from emp
select trunc((sysdate-hiredate)/) from Emp
15. 按年和月的格式显示员工参加工作的时间。
select to_char(hiredate,年2月到1987年5月之间(包括2月和5月)参加工作的员工。
select * from emp t where t.hiredate between to_date(的部门和最低工资。
select a.deptno, (select min(sal) from emp where deptno=a.deptno) minSal
from emp a group by a.deptno
select a.deptno, (select min(sal) from Emp where deptno=a.deptno) minSal
from Emp a group by a.deptno
19. 统计每个部门工资在1400元以上的所有员工的工资总额。
select e.deptno,(select sum(sal) from emp where deptno = e.deptno) as sumsal from emp e where e.sal > group by deptno
select e.deptno,(select sum(sal) from Emp where deptno = e.deptno) from Emp e where e.sal > group by deptno
20. 统计不同工作的个数。
select count(distinct job) from emp
select count(distinct job) from Emp
21. 找出各月倒数第3天受雇的所有员工。
select * from emp where hiredate = last_day(hiredate)-
22. 找出早于12()年前受雇的员工。
select * from emp where hiredate < (select sysdate - interval 个字符的员工的姓名。
select ename from emp where LENGTH(ename)=
25. 显示不带有“R”的员工的姓名。
select ename from emp where ename not like ,) from emp
select substring(ename,0,3) from Emp
27. 显示所有员工的姓名,用“a”替换所有“A”。
select replace(ename,)年服务年限的员工的姓名和受雇日期。
select hiredate from emp where hiredate < (select sysdate - interval 天的情况所有员工的日薪金,忽略余数。
select ename,floor(sal/) from emp where to_char(last_day(hiredate),
34. 找出在(任何年份的)2月受聘的所有员工。
select * from emp where to_char(hiredate,
35. 对于每个员工显示其加入公司的天数。
select sysdate - hiredate from emp
36. 显示姓名字段的任何位置包含“A”的所有员工的姓名。
select ename from emp where ename like )||,)*))||,)*),)*)||的各种工作。
select job from emp e where(select min(sal) from emp t where t.job = e.job)> group by e.job
select job from Emp e where(select min(sal) from Emp t where t.job = e.job)> group by e.job
45. 列出在部门“SALES”(销售部)工作的员工的姓名,假定不知道销售部的部门编号。
select ename from emp where deptno = (select deptno from dept where dname = 中员工的薪金的所有员工的姓名和薪金。
select e.ename,e.sal from emp e where e.sal in (select sal from emp t where t.deptno = )
select e.ename,e.sal from Emp e where e.sal in (select sal from Emp t where t.deptno = )
48. 列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。
select e.ename,e.sal from emp e where e.sal > (select max(sal) from emp t where t.deptno = )
select e.ename,e.sal from Emp e where e.sal > (select max(sal) from Emp t where t.deptno = )
49. 列出在每个部门工作的员工数量、平均工资和平均服务期限。
select deptno ,count(*) as employeeNum,avg(sal) as avgSal,avg(sysdate-hiredate) as workDays from emp group by deptno
50. 列出所有员工的姓名、部门名称和工资。
select e.ename,(select d.dname from dept d where d.deptno = e.deptno) as deptName ,e.sal from emp e;
select e.ename,(select d.dname from Dept d where d.deptno = e.deptno),e.sal from Emp e;
51. 列出所有部门的详细信息和部门人数。
select d.deptno,d.dname,d.loc,(select count(*) as empnum from emp e where e.deptno = d.deptno) from dept d
select d.deptno,d.dname,d.loc,(select count(*) from Emp e where e.deptno = d.deptno) from Dept d
52. 列出各种工作的最低工资。
select job,min(sal) from emp group by job
select job,min(sal) from Emp group by job
53. 列出各个部门的MANAGER(经理)的最低薪金。
select e.deptno,(select min(t.sal) from emp t where t.deptno = e.deptno) from emp e group by e.deptno
select e.deptno,(select min(t.sal) from Emp t where t.deptno = e.deptno) from Emp e group by e.deptno
54. 列出所有员工的年工资,按年薪从低到高排序。
select sal* from emp order by sal desc
select sal* from Emp order by sal desc
55. 列出工资最高的员工信息。
select * from emp where sal = (select max(sal) from emp )
select * from Emp where sal = (select max(sal) from Emp )
hql和sql练习题的更多相关文章
- SQL练习题完整(做完你就是高手)
SQL 练习题答案 一.补充作业一. 设有三个关系: S(SNO, SNAME, AGE, SEX,Sdept) SC(SNO, CNO ...
- 二。Hibernate 查询 HQL、SQL方式
hibernate的查询1.HQL方式:所有查询都是根据java对象名来完成,对象名替换表名2.SQL方式:保留原来的sql查询风格3.可以通过设置第一条和最大条数来实现各种数据库的分页查询4.通过B ...
- HQL和SQL查询
转自http://blog.csdn.net/aaa1117a8w5s6d/article/details/7757097 HQL和SQL的区别 标签: sqlhibernatejavasessio ...
- 50道sql练习题和答案
最近两年的工作没有写过多少SQL,感觉水平下降十分严重,网上找了50道练习题学习和复习 原文地址:50道SQL练习题及答案与详细分析 1.0数据表介绍 --1.学生表 Student(SId,Snam ...
- 深入HQL学习以及HQL和SQL的区别
HQL(Hibernate Query Language) 是面向对象的查询语言, 它和 SQL 查询语言有些相似. 在 Hibernate 提供的各种检索方式中, HQL 是使用最广的一种检索方式. ...
- SQL练习题汇总(Sqlserver和Mysql版本)
所需表及数据执行脚本: CREATE TABLE STUDENT (SNO ) NOT NULL, SNAME ) NOT NULL, SSEX ) NOT NULL, SBIRTHDAY DATET ...
- Hibernate 的HQL和sql有什么区别
转自:https://blog.csdn.net/haozhugogo/article/details/54575802sql 面向数据库表查询 hql 面向对象查询 hql : from 后面跟的 ...
- 面试题: 数据库 sql优化 sql练习题 有用 学生表,课程表,成绩表,教师表 练习
什么是存储过程?有哪些优缺点? 什么是存储过程?有哪些优缺点? 存储过程就像我们编程语言中的函数一样,封装了我们的代码(PLSQL.T-SQL). 存储过程的优点: 能够将代码封装起来 保存在数据库之 ...
- HQL和SQL的区别
1.hql与sql的区别 sql 面向数据库表查询 hql 面向对象查询 hql : from 后面跟的 类名+类对象 where 后 用 对象的属性做条件 sql: from 后面跟的是表名 ...
随机推荐
- asp.net core部署时自定义监听端口,提高部署的灵活性
另一种方式 https://www.cnblogs.com/stulzq/p/9039836.html 代码截图: 贴一下代码,方便复制: //默认端口号5000 string port = &quo ...
- ssh实现办公室电脑连接家中的电脑
友情提示:如果您不知道您家路由器管理页面的密码,请您忽略此文. 问题背景: 家中有台笔记本电脑,它是通过家中的路由器与外界联网的,这时,我想通过ssh服务让公司的电脑能连上我家中的笔记本. 可以画个图 ...
- 第六周-总结&结对编程
1.结对编程 结对编程的Partner依旧是郑蕊师姐(博客:http://www.cnblogs.com/zhengrui0452/) 我们一起改进的是郑蕊师姐做的“四则运算” 郑蕊师姐之前完成四则运 ...
- 《Linux内核设计与实现》课本第四章学习总结
进程调度 4.1 多任务 多任务操作系统就是能同时并发的交互执行多个进程的操作系统. 多任务系统分为两种: 抢占式多任务:Linux提供了抢占式的多任务模式,由调度程序来决定什么时候停止一个进程的运行 ...
- 网络:Session原理及存储
一.Session的工作流程 二.会话保持 会话保持是负载均衡最常见的问题之一,会话保持是指在负载均衡器上实现的一种机制,可以识别客户端与服务器之间交互过程的关连性,在作负载均衡的同时还保证一系列相关 ...
- answer my questions from the book<构建之法>.
1)何为文档:文档时在一个项目进行的一生中所有记忆的集合.有需求分析.功能设计.在实现功能过程中也可以有一系列文档记录.测试文档等等. 2)结对工作等找队友会花费大量时间致耽误项目否:正如老师所讲,从 ...
- git 使用ssh密钥
一.查看仓库支持的传输协议 1.1查看仓库支持的传输协议 使用命令 git remote -v 查看你当前的 remote url root@zengyue:/home/yuanGit# git re ...
- XShell+Xmanager实现在XShell中显示远程服务器的图形界面
http://blog.csdn.net/linghao00/article/details/8768435
- Eclipse: Difference between clean, build and publish
https://stackoverflow.com/questions/5656989/eclipse-difference-between-clean-build-and-publish http: ...
- LY tomcat 的闪退问题
http://www.cnblogs.com/1693977889zz/archive/2018/04/06/8726920.html 在bin文件夹里打开此文件setclasspath.bat 举例 ...