Lec10 - SQLexercises2
Lec10 - SQLexercises2
Lecture 10
Problem 1
• Consider the following database:
• emp (eno, ename, bdate, title, salary, dno)
• proj (pno, pname, budget, dno)
• dept (dno, dname, mgreno)
• workson (eno, pno, resp, hours)
• Questions:
1) Write an SQL query that returns the project number and name for projects with a budget greater than
$100,000.
2) Write an SQL query that returns all works on records where hours worked is less than 10 and the
responsibility is 'Manager'.
3) Write an SQL query that returns the employees (number and name only) who have a title of 'EE' or
'SA' and make more than $35,000.
4) Write an SQL query that returns the employees (name only) in department 'D1’ ordered by
decreasing salary.
5) Write an SQL query that returns the departments (all fields) ordered by ascending department name.
6) Write an SQL query that returns employee name, department name,
and employee title.
7) Write an SQL query that returns the project name, hours worked, and
project number for all works on records where hours > 10.
8) Write an SQL query that returns the project name, department name,
and budget for all projects with a budget < $50,000.
9) Write an SQL query that returns the employee numbers and salaries
of all employees in the 'Consulting' department ordered by
descending salary.
10) Write an SQL query that returns employee name, project name,
employee title, and hours for all works on records.
Problem 2
Question:
1) Display name and commission of all the salesmen.
2) Retrieve salesman id of all salesmen from orders table without any
repeats.
3) Display names and city of salesman, who belongs to the city of Paris.
4) Display all the information for those customers with a grade of 200.
5) Display the order number, order date and the purchase amount for
order(s) which will be delivered by the salesman with ID 5001.
6) Display all the customers, who are either belongs to the city New
York or not had a grade above 100.
7) Find those salesmen with all information who gets the commission
within a range of 0.12 and 0.14.
8) Find all those customers with all information whose names are
ending with the letter 'n’
9) Find those salesmen with all information whose name
containing the 1st character is 'N' and the 4th character is 'l' and
rests may be any character.
10)Find that customer with all information who does not get any
grade except NULL.
11)Find the total purchase amount of all orders.
12)Find the number of salesman currently listing for all of their
customers.
13)Find the highest grade for each of the cities of the customers.
14)Find the highest purchase amount ordered by each customer
with their ID and highest purchase amount.
15)Find the highest purchase amount on a date '2012-08-17' for
each salesman with their ID.
16)Find the highest purchase amount with their customer ID and
sa3ba msh htgebha
order date, for only those customers who have the highest
purchase amount in a day is more than 2000.
17)Write a SQL statement that counts all orders for a date August
17th, 2012.
18)Find the name and city of those customers and salesmen who
lives in the same city.
19)Find the names of all customers along with the salesmen who
works for them.
20)Display all those orders by the customers not located in the
same cities where their salesmen live.
21)Display all the orders issued by the salesman 'Paul Adam' from
the orders table.
22)Display all the orders which values are greater than the average
order value for 10th October 2012.
23)Find all orders attributed to salesmen in Paris.
24)Extract the data from the orders table for the salesman who
earned the maximum commission.
25)Display all the orders that had amounts that were greater than at
least one of the orders from September 10th 2012.
26)display only those customers whose grade are, in fact, higher
than every customer in New York.