You are on page 1of 3

SQL QUERIES WORKSHOP

Employee Table

FieldName Null? DataType


Emp_Id Not Null VARCHAR(4)
Name VARCHAR(25)
Position VARCHAR(15)
Hire_Date DATE
Salary Number
Brach_Code Not Null VARCHAR(2)
Department VARCHAR(15)
Supervisor VARCHAR(4)

Sample Records:
Branch
EmpID Name Position H_Date Salary Code Department Supervisor
1001 Kennedy Director 16-jan-84 50000 1 Sales 3691
1045 Smith Salesman 16-Jan-84 20000 1 Accounts 3255
1271 Stewart Clerk 12-May-94 21500 1 Admin 3876
1534 Bell Supervisor 28-Nov-95 18000 4 Admin 3876
1653 Walker Secretary 03-Aug-87 15500 2 Technical 3876
2244 Chung Programmer 09-Apr-96 30000 3 Sales  3255
2906 Stein Salesman 09-apr-96 31000 2 Sales  
3198 Roxburgh Manager 21-sep-84 20000 1 Technical  
3255 Young Clerk 19-mar-92 28000 3 Admin  
4102 Technical
Monaghan Manager 13-Jun-93 21000 2  
Sales 3255
4206 Gomatam Engineer 12-may-94 19500 2
4218 Accounts 4206
Hamilton Salesman 03-aug-87 14500 3
4936 Accounts 4206
Newman technician 23-jul-97 16000 4
5833 Nicholson Accountant 25-aug-92 20000 4 Admin  
6223 Cohen Manager 30-jun-85 17000 4 Technical  
7663 Moore Salesman 08-sep-88 19500 5 Sales  
8253 Bradley Chief Clerk 21-feb-88 30000 5 Sales 3255
9743 Evans Supervisor 15-Aug-92 18000 5 Technical 7663
9773 Fletcher Manager 13-jun-93 20000 1 Admin 3255
3691 Adams Supervisor 29-oct-87 30000 2 Admin  
3876 Hill technician 01-oct-8 16000 3 Accounts  

Branch Table
Name Null? Type

Brach_code Not Null VARCHAR(2)


Brach_Name VARCHAR(15)
City VARCHAR(15)
Manager_ID VARCHAR(4)

Sample Records
Br_code Branc_Name City Manager

01 South London 1001


02 West Liverpool 4206
03 East York 7663
04 North Aberdeen 3876
05 Europe Paris

Now try to answer the following queries and try to get the output :

1. Show a list of the names and positions of all employees in brach 03.
2. Show all details for employees working in Admin Departments.
3. Show all details for employees earning more than 20000.
4. Show the names, hire dates and department of employees hierd on or
before 1st jan 1990.
5. Show all details of employees in Accounts, Sales and IT departments.
6. Show the names of employee with names beginning with B.
7. Show the names of all employees in Sales department and earning more
than 18000.
8. Show the names of all employees in Accounts and Sales department.
9. Show the names of all employees NOT in the Accounts or the Sales
department.
10. Show the names, department and salaries of all employees in the Accounts
or Sales department, earning less than 18000.
11. Show the names, positions, branch code and department of all employee in
sequence of name within each branch and department.
12. The annual salaries of all Technical employees is to be increased by £400
this month plus a further 5% next month. Show the names and new annual
salaries.
13. List the names of employees whose names are longer than six characters.
14. Select the department names in upper case characters.
15. Calculate the number of months that Smith has been employed.
16. Calculate the average salary and total salary of all employees.
17. Calculate the number of employees in the sales department.
18. Find out the highest salary in Accounts department.
19. Find out the highest salary in all department.
20. List the branches with more than 5 employees.
21. List the names of each employee and the name of the branch they work in.
22. List the name of each branch and the number of people employed in it.
23. List the branch code ad name of each branch and no. of people employed
in it.
24. Find out the name, position and salary of the employee with the highest
salary.
25. List the employee names and salaries for employees who earn more than
the average for their branch.
26. List the branches that do not employ any Clerks.
27. List the names of branches where there are at least two salesmen.
28. List the names and position of employees who are earning the highest
salary for each position.
29. Find the names of employees whose salary is more than the maximum
salary of anyone working at the same branch as Walker.
30. Find the names of employees whose salary is more than the average of
those working in branch 02 and who are in the same position as Young.

You might also like