Queries 1
Queries 1
From the following table, write a SQL query to find the details of those
salespeople who come from the 'Paris' City or 'Rome' City. Return salesman_id,
name, city, commission.
Sample Output:
salesman_id name city commission
5002 Nail Knite Paris 0.13
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
2. From the following table, write a SQL query to find the details of the
salespeople who come from either 'Paris' or 'Rome'. Return salesman_id, name,
city, commission.
Sample Output:
salesman_id name city commission
5002 Nail Knite Paris 0.13
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
3. From the following table, write a SQL query to find the details of those
salespeople who live in cities other than Paris and Rome. Return salesman_id,
name, city, commission.
Sample Output:
salesman_id name city commission
5001 James Hoog New York 0.15
5005 Pit Alex London 0.11
5003 Lauson Hen San Jose 0.12
4. 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.
5. 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
Sample Output:
salesman_id name city commission
5002 Nail Knite Paris 0.13
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
5003 Lauson Hen San Jose0.12
6. From the following table, write a SQL query to select orders between 500 and
4000 (begin and end values are included). Exclude orders amount 948.50 and
1983.43. Return ord_no, purch_amt, ord_date, customer_id, and salesman_id.
Sample Output:
ord_no purch_amt ord_date customer_id salesman_id
70005 2400.60 2012-07-27 3007 5001
70003 2480.40 2012-10-10 3009 5003
70013 3045.60 2012-04-25 3002 5001
7. 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.
Sample Output:
salesman_id name city commission
5001 James Hoog New York 0.15
8. From the following table, write a SQL query to find the details of all
salespeople except those whose names begin with any letter between 'A' and 'L'
(not inclusive). Return salesman_id, name, city, commission.
Sample Output:
salesman_id name city commission
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
9. 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..
Sample Output:
customer_id cust_name city grade salesman_id
3007 Brad Davis New York 200 5001
3001 Brad Guzan London 5005
10. From the following table, write a SQL query to find the details of the
customers whose names end with the letter 'n'. Return customer_id, cust_name,
city, grade, salesman_id
Sample Output:
customer_id cust_name city grade salesman_id
3008 Julian Green London 300 5002
3004 Fabian Johnson Paris 300 5006
3009 Geoff Cameron Berlin 100 5003
3001 Brad Guzan London 5005
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.
Sample Output:
salesman_id name city commission
5002 Nail Knite Paris 0.13
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.
Sample Output:
customer_id cust_name city grade salesman_id
3001 Brad Guzan London 5005
13. From the following table, write a SQL query to locate the employees whose
last name begins with the letter 'D'. Return emp_idno, emp_fname, emp_lname
and emp_dept.
Sample Output:
emp_idno emp_fname emp_lname emp_dept
843795 Enric Dosio 57
444527 Joseph Dosni 47
Operators:
1. 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.
Sample table: customer
2. From the following table, write a SQL query to find all the customers in ‘New
York’ city who have a grade value above 100. Return customer_id, cust_name,
city, grade, and salesman_id.
3. From the following table, write a SQL query to find customers who are from the
city of New York or have a grade of over 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 details of all orders
excluding those with ord_date equal to '2012-09-10' and salesman_id higher than
5005 or purch_amt greater than 1000.Return ord_no, purch_amt, ord_date,
customer_id and salesman_id.
Sample table : orders
7. 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.
8. From the following table, write a SQL query to find details of all orders with a
purchase amount less than 200 or exclude orders with an order date greater than
or equal to '2012-02-10' and a customer ID less than 3009. Return ord_no,
purch_amt, ord_date, customer_id and salesman_id.
9. From the following 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 and purchase amount less than 1000.
10. From the following table, write a SQL query to find the details of all
employees whose last name is ‘Dosni’ or ‘Mardy’. Return emp_idno, emp_fname,
emp_lname, and emp_dept.
12. From the following table, write a SQL query to find the employees who work
at depart 47 or 63. Return emp_idno, emp_fname, emp_lname, and
emp_dept.