SQL Practice Queries
SQL Practice Queries
T. Y. B. C. A.
BCA -308 (Practical based on BCA-303)
Teaching Scheme
Examination Scheme
(per week)
Internal External Total
Th. Pr.
(hours) (hours) Th. Pr. Th. Pr. Th. Pr.
(marks) (marks) (marks) (marks) (marks) (marks)
- 3 - 30 - 70 - 100
University Examination Duration : 3 Hours(per batch)
41. Produce the name and city of all the customers with the same rati as Hardik'.
42. Extract all orders of Miti.
43. Extract all orders of Baroda's salesmen.
44. Find all orders of the salesman who services 'Hardik'
45. List all orders that are greater than the average of April 10, 1997
46. Find all orders attributed to salesmen in 'London'.
47. List the commission of all salesmen serving customers in 'London'.
48. Find all customers whose cnum is 1000 above than the snum of Niraj.
49. Count the no. of customers with the rating above than the average of 'Surat'.
50. List all orders of the customer 'Chandresh'.
51. Produce the name and rating of all customers who have above average orders.
52. Find all customers with orders on 3rd Oct., 1997 using correlate sub query.
53. List the name and number of all salesmen who has more than Zero customer.
54. Calculate the total amount ordered on each day eliminating the days where the total amount
was not at least Rs. 2000 above the maximum amount of that day.
55. Using correlated sub query find the name and number of all customer with rating equal to
maximum for their city.
56. Select the name and number of all salesmen who have customers their cities.
57. find all salesmen who have customers with rating > 300
58. List all salesmen with customers located in their cities.
59. Find all salesmen for whom there are customers that follow them alphabetical order.
60. Find all customers having rating greater than any customer in 'Rome'.
61. List all order that has amount grater than at least one of the orders from 6th October, 1997.
62. Find all orders with amounts smaller than any amount for a customer in 'Rome'.
63. Find all the customers who have greater rating than every customer in 'Rome'.
64. Select all customers whose rating doesn't match with any rating customer of 'Surat'.
65. List all customers whose ratings are equal to or greater than ANY 'Niraj'
66. Find out which salesman produce largest and smallest orders on each date.
67. 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 RATIN'.
68. Insert a row into salesmen table with the values snum is 100 salesman name is Rakesh, city is
unknown and commission is 14%.
69. Insert a row in to customer table with values London, Pratik a 2005 for the columns city, name
and number.
70. Create another table London staff having same structure as salesman table.
71. Insert all the rows of salesmen table with city London in the London staff table.
72. Create another table Day totals with two attributes date and total and insert rows into this table
from order table.
73. Create a duplicate of the salesmen table with a name Multicust. Now delete all the rows from
the salesmen table.
74. Get back all the rows of salesmen table from its duplicate table.
75. Remove all orders from customer Chandresh from the orders table.
76. Set the ratings of all the customers of Piyush to 400.
77. Increase the rating of all customers in Rome by 100.
78. Salesman Miti has resigned. Reassign her number to a new salesman Gopal whose city
is Bombay and commission is 10%.
79. Double the commission of all salesmen of London.
80. Set ratings for all customers in London to NULL.
Page 54 of 56
HAMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN
81. Suppose we have a table called sales Manager with the same definition as Salesmen
table. Company decides to promote salesmen having total order more than 5000 to
Sales Manager. Fill up the Sales Manager table.
82. Assume that we have a table called smcity. Store the information of all salesmen with the
customers in their home cities into smcity.
83. Create a table Bonus that contains date wise maximum amount of order for all salesmen.
84. Create a table Multicust containing the salesmen with more than one customer.
85. New Delhi office has closed. Remove all customers assigned to salesmen in New Delhi.
86. Delete all salesmen who have at least one customer with a rating of 100 from salesmen table.
87. Delete the salesmen who produce the lowest order for each day.
88. Find the smallest order for each day. Reduce the commission of all salesmen by 2%
who produce this order.
89. Delete all customers with no current orders.
90. Write a command to find out the orders by date.
91. Write a command to add the item-name column to the order table.
92. Create a copy of your order table. Drop the original order table.
93. Write a command to create the order table so that all onum values as well as all combinations
of cnum and snum are different from one another and so that NULL values are excluded from
the date field.
94. Write a command to create the salesmen table so that the default commission is 10% with no
NULL permitted, snum is the primary key and all names contain alphabets only.
95. Give the commands to create our sample tables (salesmen, customer, orders) with all
the ecessary constraints like PRIMARY KEY, NOT NULL UNIQUE, FOREING KEY.
96. Create a view called Big orders which stores all orders larger than Rs.4000.
97. Create a view Rate count that gives the count of no. of customers at each rating.
98. Create a view that shows all the customers who have the highest ratings.
99. Create a view that shows all the number of salesman in each city.
100. Create a view that shows all the number of salesmen in each city.
101. Create a view that shows the average and total orders for each salesmen after his name and
number.
102. Create a view that shows all the salesmen with multiple customers.
103. Create a view to keep track of the total no of customers ordering, no of salesmen
taking orders, the no of orders, the average amount ordered, and the total amount ordered for
ach day.
104. Create a view Show name that shows for each order the order no, amount, salesman name nd
the customer name.
105. List all orders of salesman 'Rajesh' using Show name View along with his commission.
106. Create a view Max sales to store the name and number of salesman, along with the date, who
have the highest order on any given date.
107. Using above view, find out the name and number of salesman who have the highest order at
least two times. Store the result in another view.
108. Create a view Same city that shows the no and name and city of the customers along with the
city of the salesman serving them.
109. Create a view Commission of salesmen table to include only snum and commission field so
that through. this view someone can enter or change the ommission but only to values
between 10% and 20%.
110. Assume that the CURDATE is a constant representing current date. Give a command to create
orders table with CURDATE as a default date.
111. List all salesmen in London who had at least one customer located there as well.
112. List all salesmen in London who didn't have any customer there.
Page 55 of 56