SQL Queries
SQL Queries
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
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
Customers
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
Find all salespeople whose name starts with P and the fourth character is l.
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 salespersons commission on each order by a
customer with a rating above 100.00.
45. Count the customers with ratings above San Joses 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