SQL query excercise
SQL query excercise
1)From the following table, write a SQL query to identify the unique
salespeople ID. Return salesman_id.
2) From the following table, write a SQL query to locate salespeople who live
in the city of 'Paris'. Return salesperson's name, city.
3) From the following table, write a SQL query to locate the details of
customers with grade values above 100. Return customer_id, cust_name, city,
grade, and salesman_id.
4) From the following table, write a SQL query to find customers who are
either from the city 'New York' or who do not have a grade greater than 100.
Return customer_id, cust_name, city, grade, and salesman_id.
5) From the following table, write a SQL query to identify customers who do
not belong to the city of 'New York' or have a grade value that exceeds 100.
Return customer_id, cust_name, city, grade, and salesman_id.
6) From the following table, write a SQL query to find the details of those
salespeople whose commissions range from 0.10 to0.12. Return salesman_id,
name, city, and commission.
7) From the following table, write a SQL query to retrieve the details of all
customers whose ID belongs to any of the values 3007, 3008 or 3009. Return
customer_id, cust_name, city, grade, and salesman_id.
8) From the following table, write a SQL query to find salespeople who receive
commissions between 0.12 and 0.14 (begin and end values are included).
Return salesman_id, name, city, and commission.
9) From the following table, write a SQL query to retrieve the details of the
salespeople whose names begin with any letter between 'A' and 'L' (not
inclusive). Return salesman_id, name, city, commission.
10) From the following table, write a SQL query to retrieve the details of the
customers whose names begins with the letter 'B'. Return customer_id,
cust_name, city, grade, salesman_id..
11) From the following table, write a SQL query to find the details of those
salespeople whose names begin with ‘N’ and the fourth character is 'l'. Rests
may be any character. Return salesman_id, name, city, commission.
12) From the following table, write a SQL query to find all those customers
who does not have any grade. Return customer_id, cust_name, city, grade,
salesman_id.
13) From the following table, write a SQL query to calculate total purchase
amount of all orders. Return total purchase amount.
14) From the following table, write a SQL query to count the number of
customers. Return number of customers.
15) From the following table, write a SQL query to determine the number of
customers who received at least one grade for their activity.
16) From the following table, write a SQL query to find the highest grade of
the customers in each city. Return city, maximum grade.
17) From the following table, write a SQL query to find the highest purchase
amount ordered by each customer on a particular date. Return, order date and
highest purchase amount.
18) From the following table, write a SQL query to find the highest order
(purchase) amount by each customer on a particular order date. Filter the
result by highest order (purchase) amount above 2000.00. Return customer
id, order date and maximum purchase amount.
19) From the following table, write a SQL query to determine the maximum
order amount for each customer. The customer ID should be in the range
3002 and 3007(Begin and end values are included.). Return customer id and
maximum purchase amount.
Sample Output:
customer_id max
3002 5760.00
3007 2400.60
3004 1983.43
3003 75.29
3005 948.50
20) From the following table, write a SQL query to determine the maximum
order (purchase) amount generated by each salesperson. Filter the rows for
the salesperson ID is in the range 5003 and 5008 (Begin and end values are
included.). Return salesperson id and maximum purchase amount.
Sample Output:
salesman_id max
5005 270.65
5003 2480.40
5007 75.29
5006 1983.43
21) From the following table, write a SQL query to count the number of orders
based on the combination of each order date and salesperson. Return order
date, salesperson id
Sample Output:
ord_date salesman_id count
2012-07-27 5001 1
2012-08-17 5007 1
2012-04-25 5001 1
2012-09-10 5002 1
2012-10-05 5002 1
2012-10-10 5003 1
2012-09-10 5005 1
2012-08-17 5003 1
2012-06-27 5002 1
2012-09-10 5001 1
2012-10-05 5001 1
2012-10-10 5006 1
SQL SUBQUERIES
22) From the following tables, write a SQL query to find all the orders issued by
the salesman 'Paul Adam'. Return ord_no, purch_amt, ord_date, customer_id
and salesman_id.
23) From the following tables write a SQL query to find all orders generated by
the salespeople who may work for customers whose id is 3007. Return
ord_no, purch_amt, ord_date, customer_id, salesman_id.
24) From the following tables, write a SQL query to find all the orders
generated in New York city. Return ord_no, purch_amt, ord_date, customer_id
and salesman_id.
25) From the following tables, write a SQL query to find those salespeople
who earned the maximum commission. Return ord_no, purch_amt, ord_date,
and salesman_id.
26) From the following tables write a SQL query to find those orders, which
are higher than the average amount of the orders. Return ord_no, purch_amt,
ord_date, customer_id and salesman_id.
JOINS
27) 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.
28) From the following tables write a SQL query to locate those salespeople
who do not live in the same city where their customers live and have received
a commission of more than 12% from the company. Return Customer Name,
customer city, Salesman, salesman city, commission.
29) 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.
30) From the following tables write a SQL query to display the customer name,
customer city, grade, salesman, salesman city. The results should be sorted
by ascending customer_id.