0% found this document useful (1 vote)
412 views3 pages

Practical 6

This document provides the schema and sample data for 3 tables - SALESMEN, CUSTOMER, and ORDER. It then lists 65 queries to perform on these tables to practice different SQL skills like joins, aggregation functions, sorting, filtering and more. The tables contain salesperson, customer and order details with fields like name, city, rating, order number, amount etc.

Uploaded by

Urvish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
412 views3 pages

Practical 6

This document provides the schema and sample data for 3 tables - SALESMEN, CUSTOMER, and ORDER. It then lists 65 queries to perform on these tables to practice different SQL skills like joins, aggregation functions, sorting, filtering and more. The tables contain salesperson, customer and order details with fields like name, city, rating, order number, amount etc.

Uploaded by

Urvish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical 6: Displaying data from Multiple Tables (join)

TABLE: SALESMEN
Column Data Type Size Attributes
Name
SNUM Varchar2 6 Primary key/first letter must start with ‘S’
SNAME Varchar2 20 Not null
CITY Varchar2 15
COMM Number 5,2

SNUM SNAME CITY COMM


S1001 Piyush London 0.12
S1002 Niraj San jose 0.13
S1003 Miti London 0.11
S1004 Rajesh Barcelona 0.15
S1005 Haresh New york 0.10
S1006 Ram Bombay 0.10
S1007 Nehal Delhi 0.09
TABLE: CUSTOMER
Column Data Type Size Attributes
Name
CNUM Varchar2 6 Primary key/first letter must start with ‘C’
CNAME Varchar2 20 Not null
CITY Varchar2 15
RATING Number 5
SNUM Varchar2 6

CNUM CNAME CITY RATING SNUM


C2001 Hardik London 100 S1001
C2002 Geeta Rome 200 S1003
C2003 Kavish San jose 200 S1002
C2004 Dhruv Berlin 300 S1002
C2005 Pratham London 100 S1001
C2006 Vyomesh San jose 300 S1007
C2007 Kirit Rome 100 S1004
TABLE: ORDER
Column Data Type Size Attributes
Name
ONUM Varchar2 6 Primary key/first letter must start with ‘O’
AMT Number 10,2 Not null
ODATE Date
CNUM Varchar2 6
SNUM Varchar2 6

ONUM AMT ODATE CNUM SNUM


O3001 18.69 10-Mar-90 C2008 S1007
O3003 767.19 10-Mar-90 C2001 S1001
O3002 1900.10 03-Oct-90 C2007 S1004
O3005 5160.45 04-Oct-90 C2003 S1002
O3006 1098.16 10-Mar_90 C2008 S1007
O3009 1713.23 10-April-90 C2002 S1003
O3007 75.75 10-April-90 C2004 S1002
O3008 4723.00 10-May-90 C2006 S1001
O3010 1309.95 10-May-90 C2004 S1002
O3011 9891.88 10-June-90 C2006 S1001
Perform following queries.
SELECT
1. Display all the information of salesmen.
2. Display snum,sname,city from salesmen table.
3. Display odate,snum,onum and amt from orders.
4. Display the information of orders without duplication.
5. List of sname, city from salesmen where city is ‘LONDON’.
6. List all records of customers where rating is equal to 100.
7. Write a select command that produces the order number,amount and date for all rows in
the order table.
8. Produces all rows from the customer table for which the salesperson’s number is S1001.
9. Display the salesperson table with the column in the following order:
city,sname,snum,comm.
10. Write a select command that produces the rating followed by the name of each customer
in SAN JOSE.
11. Display SNUM values of all salesmen without any repeat.
OPERATORS
12. List all customers with a rating above 200.
13. List all customers in SAN JOSE who have a rating above 200.
14. List all customers who were either located in SAN JOSE or had a rating above 200.
15. List of all customers who were either located in SAN JOSE or not rating above 200.
16. List of all customers who were not located in SAN JOSE or rating is not above 200.
17. Write a query that will give you all orders for more than $1000.
18. Write a query that will give you the names and cities of all salesmen in LONDON with a
commission above 0.10.
19. Write a query on the customers table whose output will exclude all customers with a
rating <= 100 and they are located in ROME.
SPECIAL OPERATORS
20. Display all salesmen that were located in either BARCELONA or LONDON(use IN
keyword).
21. Find all customers matched with salesmen S1001,S1007 and S1004.
22. Display all salesmen with commission between 0.10 and 0.12.
23. Select all customers whose names fall in a ‘A’ and ‘G’ alphabetical.
LIKE OPERATORS.
24. List all the customers whose names begin with ‘G’.
25. List all salesmen whose sname start with letter ‘P’ and end letter is ‘H’.
NULL OPERATORS.
26. Find all records in customer table with NULL values in the city column.
27. Write a two queries that will produce all orders taken on October 3 rd or 4th ,1990
( use IN operator and Use BETWEEN operator )
28. Write a query that selects all of the customers matched with S1001 and S1002.
29. Write a query that will produce all of the customers whose names begin with a letter
from A to H.
30. Write a query that selects all customers whose names begin with ‘C’.
31. Write a query that selects all orders without ZEROS or NULLS in amt field..
FUNCTIONS
32. Display sum of amt,average of orders.
33. To count the numbers of salesmen without duplication in the orders tables.
34. Count the rating of customers (with NULL and without NULL).
35. Find the largest order taken by each salesperson.(hint: use group by)
36. Find the largest order taken by each salesperson on each date.
37. Find out which day had the higher total amount ordered.
38. Write a query that counts all orders for October 3rd.
39. Write a query that counts the number of different non-NULL city in the customer table.
40. Write a query that selects the first customer in alphabetical order whose name begin with
‘G’.
5.3
41. write a query that selects each customers smallest order.
42. Write a query that selects the highest rating in each city.
43. Write a query that counts the number of salesmen registering orders for each day(if a
salesperson has more than one order on a given day , he or she should be counted only
once)
44. Display all the information in descending orders(use column CNUM).
45. Display all the information in descending orders(use column CNUM,AMT).
46. Display sname and comm. From salesmen in descending order(in place of column name
use column number).
47. Assume each salesperson has a 0.12 commission. Write a query on the orders table that
will produce the order number,the salesperson number and the amount of the
salesperson’s commission for that order.
48. Write a query on the customers table that will find the highest rating in each city. Put the
output in this form.
For the city (city) , the highest rating is: (rating).
49. Write a query that lists customers in descending order of rating. Output the rating field
first, followed by the customer’s name and number.
50. Write a query that totals the orders for each day and places the results in descending
order.
JOIN
51. Show the names of all customers matched with the salesmen serving them.
52. Write a query that lists each order number followed by the name of the customer who
made the order.
53. Write a query that gives the names of both the salesperson and the customer for each
order after the order number.
54. Write a query that produces all customers serviced by salesmen with a commission
above 0.12. Output the customer’s name, the salesperson’s name and the salesperson’s
rate of commission.
55. Write a query that calculates the amount of the salesperson’s commission on each order
by a customer with a rating above 100.
OTHERS
56. List all customer located in cities where salesperson ‘PIYUSH’ has customer.
57. List all salesmen who are living in same city without duplicate rows.
58. Extract all orders of ‘PIYUSH’.
59. Extract all orders of LONDON’S salesmen.
60. Find all customers whose cnum is 1000 above than the snum of ‘PIYUSH’.
61. Count the no. of customers with the rating above than average Rating of ‘LONDON’.
62. Produce the name and rating of all customers who have above average Rating.
63. List all salesmen with customers located in their cities.
64. Select all customers whose rating doesn’t match with any rating customer of ‘SAN JOSE’.
65. Create a union of two queries that shows the names,cities and ratings of all customers.
Those with rating of >=200 should display ‘HIGH RATING’ and those with <200 should
display ‘LOW RATING’.
66. Find all customers with orders on 3rd october 1990 using correlate sub query.
67. Find all customers having rating greater than any customer in ‘ROME’.
68. Insert a row into salesmen table with the values snum is s1008,salesmen name is
‘RAKESH’, city is unknown and commission is 14%.
69. Create another table London_staff having same structure as salesmen table.
70. Delete all orders from customer ‘PIYUSH’ from the order table.
71. Set the ratings of all the customers of PIYUSH to 400.
72. Increase the rating of all the customers in ROME by 100.
73. Double the commission of all salesmen of LONDON.
74. Set ratings for all customers in LONDON to NULL.
75. Delete all salesmen who have at least one customer with a rating of 100 from salesmen
table.

You might also like