0% found this document useful (0 votes)
17 views

SQL Queries

This document provides tables of salespeople, customers, and orders to practice writing SQL queries. It includes the structure of the tables with columns and sample data. It then provides 50 questions as examples of queries to write using the tables, covering topics like selecting data, filtering, aggregating, joining tables, and using functions.

Uploaded by

Sambhav Bahadure
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

SQL Queries

This document provides tables of salespeople, customers, and orders to practice writing SQL queries. It includes the structure of the tables with columns and sample data. It then provides 50 questions as examples of queries to write using the tables, covering topics like selecting data, filtering, aggregating, joining tables, and using functions.

Uploaded by

Sambhav Bahadure
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

GAIN PRACTICE ON SQL USING THE TABLES AND QUESTIONS GIVEN BELOW.

Create the following tables set the primary and foreign key references on the table. Insert the
following rows in the table.

Salespeople
SNUM SNAME CITY COMM
1001 Peel London .12
1002 Serres San Jose .13
1004 Motika London .11
1007 Rifkin Barcelona .15
1003 AxelRod New York .10
1005 Fran London .26

Customers
CNUM CNAME CITY RATING SNUM
2001 Hoffman London 100 1001
2002 Giovanni Rome 200 1003
2003 Liu San Jose 200 1002
2004 Grass Berlin 300 1002
2006 Clemens London 100 1001
2008 Cisneros San Jose 300 1007
2007 Pereira Rome 100 1004
Orders
ONUM AMT ODATE CNUM SNUM
3001 18.69 10/03/96 2008 1007
3003 767.19 10/03/96 2001 1001
3002 1900.10 10/03/96 2007 1004
3005 5160.45 10/03/96 2003 1002
3006 1098.16 10/03/96 2008 1007
3009 1713.23 10/04/96 2002 1003
3007 75.75 10/04/96 2002 1003
3008 4723 .00 10/05/96 2006 1001
3010 1309.95 10/06/96 2004 1002
3011 9891.88 10/06/96 2006 1001
Queries
1. List all the columns of the Salespeople table.
Solution:-
2. List all customers with a rating of 100.
3. Find all records in the Customer table with NULL values in the city column.
4. Find the largest order taken by each salesperson on each date.
5. Arrange the Orders table by descending customer number.
6. Find which salespeople currently have orders in the Orders table.
7. List names of all customers matched with the salespeople serving them.
8. Find the names and numbers of all salespeople who had more than one customers

9. Count the orders of each of the salespeople and output the results in descending order.
10. List the Customer table if and only if one or more of the customers in the Customer table are
located in San Jose.
11. Match salespeople to customers according to what city they lived in.
12. Find the largest order taken by each salesperson.
13. Find customers in San Jose who have a rating above 200.
14. List the names and commissions of all salespeople in London.;
15. List all the orders of salesperson Motika from the Orders table.
16. Find all customers with orders on October 3.
17. Give the sums of the amounts from the Orders table, grouped by date, eliminating all those
dates where the SUM was not at least 2000.00 above the MAX amount.
18. Select all orders that had amounts that were greater than at least one of the orders from
October 6
19. Write a query that uses the EXISTS operator to extract all salespeople who have customers
with a rating of 300.
20. Find all pairs of customers having the same rating.
21. Find all customers whose CNUM is 1000 above the SNUM of Serres.
22. Give the salespeople’s commissions as percentages instead of decimal numbers.
23. Find the largest order taken by each salesperson on each date, eliminating those MAX orders
which are less than $3000.00 in value.
24. List the largest orders for October 3, for each salesperson.

25. Find all customers located in cities where Serres (SNUM 1002) has customers.
26. Select all customers with a rating above 200.00.
27. Count the number of salespeople currently listing orders in the Orders table.
28. Write a query that produces all customers serviced by salespeople with a commission above
12%. Output the customer’s name and the salesperson’s rate of commission.
29. Find salespeople who have multiple customers.
30. Find salespeople with customers located in their city.
31 Find all salespeople whose name starts with ‘P’ and the fourth character is ‘l’.
31.
32. Write a query that uses a subquery to obtain all orders for the customer named Cisneros.
Assume you do not know his customer number.
33. Find the largest orders for Serres and Rifkin.
34. Extract the Salespeople table in the following order : SNUM, SNAME, COMMISSION,
CITY.
35. Select all customers whose names fall in between ‘A’ and ‘G’ alphabetical range.
36. Select all the possible combinations of customers that you can assign.
37. Select all orders that are greater than the average for October 4.
38. Write a select command using a corelated subquery that selects the names and numbers of all
customers with ratings equal to the maximum for their city.
39. Write a query that totals the orders for each day and places the results in descending order.
40. Write a select command that produces the rating followed by the name of each customer in
San Jose.
41. Find all orders with amounts smaller than any amount for a customer in San Jose.
42. Find all orders with above average amounts for their customers.
43. Write a query that selects the highest rating in each city.
44. Write a query that calculates the amount of the salesperson’s commission on each order by a
customer with a rating above 100.00.
45. Count the customers with ratings above San Jose’s average.
46. Write a query that produces all pairs of salespeople with themselves as well as duplicate rows
with the order reversed.
47. Find all salespeople that are located in either Barcelona or London.
48. Find all salespeople with only one customer.
49. Write a query that joins the Customer table to itself to find all pairs of customers served by a
single salesperson.
50. Write a query that will give you all orders for more than $1000.00

You might also like