JAva笔记

  • 格式:doc
  • 大小:37.50 KB
  • 文档页数:2

Chp1 简单查询

key point:

 简单select语句的书写

 order by 数据排序

 where条件判断

 case....when 选择语句

练习

1. 查询员工表所有数据

select * from employees

2. 打印公司里所有的manager_id

select manager_id from employees

3. 查询所员工的email全名,公司email 统一以 "@" 结尾.

select email||'@' email from employees

4. 按照入职日期由新到旧排列员工信息

select * from employees order by hire_date desc

5. 查询80号部门的所有员工

select * from employees where department_id = 80

6. 查询50号部门的员工姓名以及全年工资.

select last_name||' '||first_name name,salary*12 年薪 from employees where department_id

= 50

7. 查询50号部门每人增长1000元工资之后的人员姓名及工资.

select last_name||' '||first_name name,salary+1000 salary from employees where

department_id = 50

8. 查询80号部门工资大于7000的员工的全名与工资.

select last_name||' '||first_name name,salary from employees where department_id = 80 and

salary>7000

9. 查询80号部门工资大于8000并且提成高于0.3的员工姓名,工资以及提成

select last_name||' '||first_name name,salary,commission_PCT from employees where

department_id = 80 and salary>8000 and commission_PCT>0.3

10. 查询职位(job_id)为'AD_PRES'的员工的工资

select last_name||' '||first_name name,salary from employees where job_id = 'AD_PRES'

11. 查询工资高于7000但是没有提成的所有员工.

select * from employees where salary>7000 and commission_PCT is null

12. 查询佣金(commission_pct)为0或为NULL的员工信息

select * from employees where commission_PCT is null or commission_PCT = 0

13. 查询入职日期在1997-5-1到1997-12-31之间的所有员工信息

select * from employees where hire_date between '1-5月 -97' and '31-12月 -97'

14. 显示姓名中没有'L'字的员工的详细信息或含有'SM'字的员工信息

select * from employees where last_name||' '||first_name not like '%L%' or last_name||'

'||first_name like '%SM%'

15. 查询电话号码以5开头的所有员工信息.

select * from employees where Phone_number like '5%'

16. 查询80号部门中last_name以n结尾的所有员工信息

select * from employees where department_id = 80 and last_name like '%n'

17. 查询所有last_name 由四个以上字母组成的员工信息

select * from employees where last_name like '____%'

18. 查询first_name 中包含"na"的员工信息.

select * from employees where first_name like '%na%'

19. 显示公司里所有员工的工资级别case when

A <=5000

B >=5001 and <=8000

C >=8001 and <=15000

D >15000

select employee_id,last_name,case

when(salary<=5000) then 'A'

when(salary between 5001 and 8000) then 'B'

when(salary between 8001 and 15000) then 'C'

when(salary>15000) then 'D'

end

as 级别

from employees

20. 根据入职时间打印出员工级别(,,新员工)

资深员工 95前(包含95)

普通员工 95 -- 99(包含99)

新员工 99年后

select employee_id,last_name,hire_date,case

when(hire_date <'1-1月 -95') then '资深员工'

when(hire_date >='1-1月 -95'and hire_date <'1-1月 -00') then '普通员工'

when(hire_date >='1-1月 -00') then '新员工'

end

as 级别

from employees