1. 程式人生 > >mysql測試資料庫employees一些sql語句

mysql測試資料庫employees一些sql語句

一套SQL筆試題
1、查詢整個職員表的所有內容。
select *
from employees
2、檢視僱員名字(last_name)。
select last_name
from employees
3、檢視僱員編號、名字和工種。
select last_name,job_id,employee_id
from employees
4、顯示所有僱員的姓名、工資並將DEPARTMENT_ID顯示為(Department_Id)。
select last_name,salary,DEPARTMENT_ID as Department_Id
from employees
5、查詢在60號部門工作的僱員。
select last_name+first_name name,department_id

from employees
where departmet_id=60
6、要求查詢職位為SH_CLERK和SA_MAN的僱員姓名(last_name)。
select last_name job_id
from employees
where job_id in ('sh_clerk','sa_man')
7、查詢職位不是SH_CLERK和SA_MAN的僱員工種及姓名。將姓名顯示為(first_name+last_name命名為”Name”)。
select first_name+last_name Name, job_id
from employees
where job_id not in ('sh_clerk','sa_man')

8、查詢哪些僱員的工資在2000到3000之間
select *
from employees
where salary between 2000 and 3000
9、查詢哪些僱員的工資不在3000到5000之間
select *
from employees
where salary not between 3000 and 5000
10、查詢first_name以D開頭,後面僅有三個字母的僱員資訊。
select *
from employees
where first_name like ‘D___' and first_name not like ‘d__ ‘
11、查詢last_name以K開頭的僱員資訊。
select last_name,first_name,department_id

from employees
where last_name like ‘k%'
12、查詢名字以字母M開頭,以l結尾,並且第三個字母為c的僱員名字(First_name)、工種和所在部門號
select first_name,job_id,department_id
from employees
where first_name like ‘m_c%l'
13、查詢哪些僱員的工種名不以SA開頭。
select job_id
from employees
where job_id not like 'sa%'
14、查詢沒有獎金的僱員資訊。
select *
from employees
where commission_pct is null
15、查詢有獎金的僱員資訊。
select *
from employees
where commission_pct is not null
16、查詢30號部門裡不是CLERK的僱員資訊。
select *
from employees
where department_id=30 and job_id not like ‘%clerk%'
17、查詢在30號部門工作或不是CLERK的僱員資訊。
select *
from employees
where department_id=30
or job_id not like ‘%clerk%'
查詢60號部門且工資大於5000的員工的資訊
select *
from employees
where department_id=60
and salary>5000
18、按字母順序顯示僱員的名字(last_name)。
select last_name
from employees
order by last_name
19、按部門號降序顯示。
select * from employees order by department_id desc
20、查詢工資高於$2000的僱員資訊,按部門號和僱員名字排序。
select * from employees where salary>2000 order by department_id,employee_id
21、選擇獎金高於5%的僱員資訊
SELECT FIRST_NAME, LAST_NAME, COMMISSION_PCT
FROM dbo.EMPLOYEES
WHERE (COMMISSION_PCT > .05)
22 查詢年工資高於50000的員工資訊
select * from employees where 12*salary>50000
23 查詢獎金高於5000的員工姓名
day
1、查出部門地區編號為1700的員工姓名
select first_name,last_name,city,department.location_id
from locations,employees,department
where locations.location_id=department.location_id
and locations.location_id=1700
2、查詢工作地區為北京的員工名及工資資訊
select first_name,last_name,salary,commission_pct,city
from locations,employees,departments
where departments.location_id=locations.location_id
and departments.department_id = employees.department_id
and departments.location_id=1700
3、查詢薪水標準為B類的員工名稱和員工薪水以及工資類別名稱
select last_name,first_name,salary,commission_pct,gra
from departments d,employees e,job_grades j
where e.salary between j.lowest and j.highest
and j.gra='b'
and d.department_id=e.department_id
4、查詢出主管Raphaely管理的員工和薪水資訊
select a.last_name+a.first_name as name, a.salary,a.commission_pct,b.last_name
from employees a,employees b
where a.department_id=b.department_id
and a.last_name like ‘%raphaely%'
5、查出僱員所在的部門,並將沒有僱員的部門的記錄也顯示出來。
select e.last_name+e.first_name as name,d.department_id
from departments d
left outer join employees e
on (e.department_id=d.department_id)
6、查詢出沒有分配部門的員工資訊
select e.last_name+e.first_name as name,e.department_id
from departments d
left outer join employees e
on (e.department_id=d.department_id)
where d.department_id is null
7、計算每個部門的平均工資和工資總和
select department_id,sum (salary) sum,avg (salary) avg
from employees
group by department_id
8、查詢每個部門的每個工種的僱員數
select count(*)num,department_id,job_id
from employees
group by department_id,job_id
9、請算出employee表中總僱員數量
select count(*)
from employee
10.請算出employee表中所有僱員的平均工資
select avg(salary)
from employee
11.請查詢出employee表中的最低工資
select min(salary)
from employee
12.請查詢出employee表中最高工資
select max(salary)
from employee
13、請計算出每個部門的平均工資、最高工資和最低工資
select max(salary) max,min(salary) min,avg(salary) avg,department_id
from employee
group by department_id
14、查詢按部門名稱分組工資總和大於4200的部門名稱、工資和
select department_name,sum(salary)
from employees e,departments d
where e.department_id=d.department_id
group by department_name
having sum(salary)>4200
test001
1.請查詢出employee表中最低工資的僱員
select last_name
from employee
where salary=(select min(salary) from employee)
2.請查詢出employee表中最高工資的僱員
select last_name
from employee
where salary=(select max(salary) from employee)
3、查詢工資高於105號僱員的last_name,並且工種與他相同的僱員情況。
select last_name,job_id,salary
from employees
where salary>(select salary from employees where employee_id='105′)
and job_id=(select job_id from employees where employee_id='105′)
4、查詢工資高於或等於30號部門工資最高額的僱員。
select last_name,salary
from employees
where salary>=(select max(salary) from employees where department_id=30)
5 查詢工資在1000到5000之間的僱員所在部門的所有人員的資訊。
select *
from employees
where department_id in
(select department_id from employees where salary between 1000 and 5000)
6 查詢工資高於60號部門所有員工的人員資訊。顯示其員工編號,last_name和工資。
select last_name,employee_id,salary
from employees
where salary>
(select max(salary) from employees where department_id=60)
7 將114號僱員的工種和部門號改為102號僱員的工種和部門號。
8、將所有與106號僱員相同工種的職工的部門號改成106號僱員所在的部門。
9、查詢工種不為SH_CLERK,並且工資小於其中任何一個SH_CLERK的僱員資訊。