SQL TS Final
SQL TS Final
Exercise:
Table: salesman
salesman_id | name | city | commission
-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12
Table: customer
customer_id | cust_name | city | grade | salesman_id
-------------+----------------+------------+-------+-------------
3002 | Nick Rimando | New York | 100 | 5001
3007 | Brad Davis | New York | 200 | 5001
3005 | Graham Zusi | California | 200 | 5002
3008 | Julian Green | London | 300 | 5002
3004 | Fabian Johnson | Paris | 300 | 5006
3009 | Geoff Cameron | Berlin | 100 | 5003
3003 | Jozy Altidor | Moscow | 200 | 5007
3001 | Brad Guzan | London | | 5005
Table: orders
ord_no purch_amt ord_date customer_id salesman_id
---------- ---------- ---------- ----------- -----------
70001 150.5 2012-10-05 3005 5002
70009 270.65 2012-09-10 3001 5005
70002 65.26 2012-10-05 3002 5001
70004 110.5 2012-08-17 3009 5003
70007 948.5 2012-09-10 3005 5002
70005 2400.6 2012-07-27 3007 5001
70010 1983.43 2012-10-10 3004 5006
70003 2480.4 2012-10-10 3009 5003
70011 75.29 2012-08-17 3003 5007
a- Write a SQL statement that create the tables above. (A SQL query for each table). 3pts
b- Write a SQL statement that displays all the information about each table.3pts
c- From the customer table, write a SQL query to find customers whose grade is 200.
Return customer_id, cust_name, city, grade, salesman_id. Write the output result. 2pts
d- From the following tables write a SQL query to find the salesperson and customer who
reside in the same city. Return Salesman, cust_name and city.
Write the output result. 2pts
e- From the orders table, write a SQL query to find all orders that meet the following
conditions. Exclude combinations of order date equal to '2012-08-17' or customer ID
greater than 3005. Write the output result. 2pts
f- From the following tables write a SQL query to find those orders where the order amount
exists between 500 and 2000. Return ord_no, purch_amt, cust_name, city. Write the
output result. 2pts
g- From the following tables write a SQL query to find the salesperson(s) and the
customer(s) he represents. Return Customer Name, city, Salesman, commission.
Write the output result. 2pts
h- From the following tables write a SQL query to find those customers with a grade less
than 300. Return cust_name, customer city, grade, Salesman name, Salesman city. The
result should be ordered by ascending customer_id. Write the output result. 2pts
i- Write a SQL statement to insert a record into the table salesman (5008
as ID, Ali Ismael as a name, Beirut as city and 0.11 as
commission).1pt
j- Delete table orders from database. 1pt
Good Luck