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

SQL_QUESTIONS

The document describes a database with two tables: Customer and Prod_Order, detailing their structure and relationships. It outlines various SQL queries that can be performed on these tables to retrieve, filter, and analyze customer and order data. The queries cover a wide range of operations including projections, conditions, and special operators.

Uploaded by

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

SQL_QUESTIONS

The document describes a database with two tables: Customer and Prod_Order, detailing their structure and relationships. It outlines various SQL queries that can be performed on these tables to retrieve, filter, and analyze customer and order data. The queries cover a wide range of operations including projections, conditions, and special operators.

Uploaded by

fijara1250
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

THE TABLES THAT ARE GOING TO BE USED ARE :-

The given database consists of two tables: Customer and Prod_Order, which store customer details and their
respective orders. The Customers table includes fields such as CID, FirstName, LastName, Email and City. Each row
represents a unique customer, identified by the CID, which acts as the primary key. This table helps in maintaining
customer-related information, including their contact details and location.

The Prod_Order table records order transactions made by customers. It contains fields such as PID, CID,
ProductName, Quantity, OrderDate, and TotalPrice. The PID is the primary key, uniquely identifying each order,
while CID serves as a foreign key, establishing a relationship between the two tables. This connection enables
tracking which customer placed a particular order. The OrderDate column captures when the order was made,
and TotalPrice reflects the cost of the order.

These two tables are related through the CID, allowing us to perform various SQL operations, such as retrieving
customer details along with their orders using JOINs, filtering orders based on specific conditions using the
WHERE clause, and analyzing sales trends using aggregate functions like SUM, COUNT, and AVG. Queries can also
be used to sort order records by date or price, update existing data, or delete unwanted records. With these
tables, we can perform a wide range of SQL operations, from basic data retrieval to complex queries, helping us
gain meaningful insights from the dataset.
→ QUESTIONS ON PROJECTION, WHERE, ALIAS OR SELECT CLAUSE.
1. WAQTD ALL THE RECORDS OF THE CUSTOMERS TABLE.

2. WAQTD ALL THE RECORDS OF THE PRODUCT_ORDER TABLE.

3. WAQTD Select the first names and last names of all customers.
4. Select only the PROD_NAME and TOTALPRICE from the PROD_ORDER table.

5. Select distinct CITY values from the CUSTOMER table.

6. Select First name and email address.


7. Select customers who live in New York.

8. Retrieve all product orders where QUANTITY > 1.

9. Get all orders placed in the year 2023.

10. Find orders where TOTALPRICE is greater than 500.

11. Retrieve orders where PROD_NAME contains the word ‘CHARGER’.

12. Get all customers whose LASTNAME starts with ‘S’.


13. Find orders where the ORDERDATE is before 01-JAN-2022.

14. Retrieve orders placed by customer ID 3.

15. Get customers who do not live in Los Angeles.

16. Retrieve customers whose EMAIL ends with "@email.com".


17. Display FIRSTNAME as NAME and CITY as LOCATION.

18. Show PROD_NAME as PRODUCT and TOTALPRICE as PRICE.

19. Retrieve all CID as CUSTOMER_ID from the PROD_ORDER table.


20. Rename ORDERDATE column as PURCHASE_DATE while retrieving data.

21. Display all customers' EMAIL as CONTACT_EMAIL.

22. Select only EMAIL and CITY from the CUSTOMER table.
23. Retrieve PID, CUSTOMERID, and ORDERDATE from the PROD_ORDER table.

24. Select FIRSTNAME, LASTNAME, and CITY of all customer.

25. Retrieve PROD_NAME and QUANTITY from PROD_ORDER.


26. Retrieve distinct PRODUCTNAME values from PROD_ORDER.

27. Display only the ORDERDATE column from the PROD_ORDER table.

28. Retrieve TOTALPRICE for all orders placed by customers.


29. Select FIRSTNAME, LASTNAME, and EMAIL from CUSTOMERS.

30. Retrieve PID and PRODUCTNAME from PRODUCT_ORDER.

31. Select the CUSTOMERID and CITY columns from CUSTOMERS.


32. Retrieve all unique ORDERDATE values from PRODUCT_ORDER.

33. Select PID, PROD_NAME, and TOTALPRICE for all orders.

34. Retrieve EMAIL addresses of all customers.


35. Display FIRSTNAME, LASTNAME, and EMAIL of customers in a single query.

36. Retrieve all orders where TOTALPRICE is less than 200.

37. Display PRODUCTNAME for all orders where QUANTITY is exactly 1.

38. Select EMAIL and CITY of customers from 'Chicago'.


39. Select PRODUCTNAME and TOTALPRICE for all orders with a TOTALPRICE greater than 300.

40. Display the FIRSTNAME, EMAIL, and PHONE of customers from 'San Diego'.

41. Select PRODUCTNAME where TOTALPRICE is between 100 and 500.

42. Retrieve FIRSTNAME as Customer_First_Name from CUSTOMERS.

43. Select PRODUCTNAME as Item and TOTALPRICE as Price from PRODUCT_ORDER.


44. Retrieve CITY as Customer_Location from CUSTOMERS.

45. Display PID as PRODUCT_Number and ORDERDATE as Date_of_Purchase.

46. Retrieve FIRSTNAME and LASTNAME concatenated as Full_Name.

47. Display QUANTITY as Items_Purchased from PRODUCT_ORDER.


48. Select PRODUCTNAME as Item_Name from PRODUCT_ORDER.

49. Show TOTALPRICE as Amount_Paid in the output.

50. Retrieve CITY as Residence and EMAIL as Primary_Contact.

51. Select ORDERDATE as Transaction_Date and PID as PRODUCT_ID.


52. Display CUSTOMERID as User_ID from CUSTOMERS.

53. Retrieve PRODUCTNAME as Ordered_Item and QUANTITY as Item_Count.

54. Retrieve FIRSTNAME as Given_Name, LASTNAME as Family_Name.

55. SELECT max total_price as highest price item.


56. SELECT min total_price as lowest price item.

57. Display CITY as Hometown from CUSTOMERS.

58. Retrieve FIRSTNAME and EMAIL as Customer_Info using concatenation.

59. Concatenate ORDERID and ORDERDATE as Order_Details.


➔ QUESTIONS ON AND, OR AND NOT OPERATOR.
60. Retrieve customers from New York AND Los Angeles.

61. Get customers with first name 'John' AND last name 'Doe'.

62. Find products ordered in July 2023 AND with a total price greater than 500.

63. Retrieve all orders where the quantity is greater than 1 AND the total price is above 100.

64. Get customers with email containing 'email.com' AND living in Chicago.

65. Find products ordered by customer ID 4 AND with a price below 500.

66. Retrieve all orders placed in 2021 AND costing more than 200.

67. Get all products ordered by customer ID 1 AND ordered in 2023.


68. Find customers living in San Diego AND having an email with 'martinez'.

69. Get customers whose first name starts with 'J' AND live in Texas (Dallas or Houston).

70. Retrieve customers from Chicago OR San Diego.

71. Get products with total price greater than 700 OR ordered in 2022.

72. Find customers whose first name is 'David' OR last name is 'Clark'.

73. Retrieve all orders made on 15-Aug-23 OR 18-Nov-23.

74. Get orders where the product name is 'Monitor' OR 'Keyboard'.

75. Find customers living in Los Angeles OR Houston.

76. Retrieve orders with quantity more than 2 OR total price above 500.
77. Find orders placed in 2021 OR 2023.

78. Get customers with first names starting with 'A' OR living in Phoenix.

79. Find orders by customer ID 7 OR 10.

80. Retrieve customers NOT from Dallas.

81. Get products NOT ordered in 2023.


82. Find orders where total price is NOT less than 100.

83. Retrieve customers whose email does NOT contain '@email.com'.

84. Get customers NOT living in New York, Los Angeles, or Chicago.

85. Retrieve orders NOT made in 2021.

86. Find customers whose first name is NOT 'James'.


87. Retrieve all orders NOT placed by customer ID 3.

88. Get all orders where the quantity is NOT 1.

89. Find orders NOT made in May.

90. Retrieve customers from New York OR Los Angeles, but NOT from Chicago.

91. Get products ordered in 2022 AND costing more than 100, OR ordered in 2023.
92. Find customers whose first name starts with 'J' AND NOT living in San Jose.

93. Retrieve orders with a quantity greater than 2 AND NOT made in 2021.

94. Get customers who are from Chicago OR Houston AND have an email ending with '@email.com'.

95. Find orders made in 2023 AND total price NOT less than 500.

96. Retrieve customers who are NOT from New York AND have a last name 'Smith' OR 'Johnson'.

97. Find all orders with product names NOT containing 'Wireless' AND ordered in 2022.

98. Get orders with a total price NOT greater than 500 OR ordered in 2021.
99. Retrieve customers whose first name starts with 'A' OR 'J' AND NOT living in Dallas.

100. Get orders made in 2023 AND NOT containing 'Wireless' in the product name.

101. Find customers who are from Los Angeles OR San Diego AND have an email ending with '@email.com'.

102. Retrieve all orders made in 2022 OR having a quantity greater than 3.

103. Get customers NOT from Phoenix AND having a last name 'Davis' OR 'Lewis'.

104. Find orders where the product name is 'Laptop' OR 'Smartphone' AND NOT ordered in 2021.

105. Retrieve customers whose email contains 'gmail' OR 'yahoo' AND NOT living in Chicago.

106. Get all orders placed by customer ID 5 AND NOT containing 'Charger' in the product name.
107. Find products ordered in 2021 OR 2022 AND NOT having a quantity less than 2.

108. Retrieve orders with a total price greater than 100 AND NOT made in December.

109. Get customers living in San Antonio OR Dallas AND NOT having 'martinez' in their email.

110. Find all orders where the total price is below 300 AND NOT placed in 2023.

111. Retrieve products ordered by customer ID 10 AND NOT containing 'Graphics' in the product name.

112. Get customers from Houston OR Philadelphia AND NOT having an email with '.edu'.
113. Find all orders placed before July 2021 OR having a total price above 700.

114. Retrieve customers whose first name starts with 'D' AND NOT from San Diego.

115. Get orders made on 10-May-22 OR 17-May-22 AND NOT by customer ID 1.

116. Find products that have a total price between 200 and 500 AND NOT ordered in 2023.

117. Retrieve customers whose last name starts with 'A' OR 'B' AND NOT from San Jose.

118. Get all orders placed in the first quarter of any year (Jan-Mar) AND NOT by customer ID 6.

119. Find customers with an email ending in '@email.com' AND NOT having 'smith' in their last name.

120. Retrieve all orders with a quantity greater than 2 OR total price below 100 AND NOT ordered in 2021.

121. Get customers from New York OR Chicago AND NOT having an email with 'brown'.
122. Find orders where the product name contains 'Drive' OR 'Router' AND NOT ordered in 2022.

123. Retrieve customers whose first name contains 'R' OR 'M' AND NOT from Los Angeles.

124. Get all orders where the product name contains 'VR' OR 'Monitor' AND NOT having a total price above 500.

125. Find customers who have an email ending with '@email.com' AND NOT living in San Antonio.

126. Retrieve orders made in August OR November AND NOT placed by customer ID 7.

127. Get products ordered by customer ID 8 OR 9 AND NOT costing more than 600.

128. Find customers who have a last name ending in 'N' OR 'S' AND NOT from Houston.

129. Retrieve orders with a total price above 200 OR quantity below 3 AND NOT made in 2022.
➔ Special Operators (IN, BETWEEN, LIKE, EXISTS, ANY, ALL, IS NULL, etc.)
130. Retrieve all customers from New York, Los Angeles, or Chicago.

131. Find customers whose CID is between 3 and 7.

132. Retrieve all orders placed between '01-JAN-22' and '31-DEC-22'.

133. Find all customers whose first name starts with 'J'.

134. Retrieve orders where the product name contains 'CHARGER'.

135. Get all customers whose email ends with 'EMAIL.COM'.


136. Retrieve products where the TOTALPRICE is greater than any order placed by CID = 1.

137. Retrieve orders where the total price is higher than all orders placed by customer ID 7.

138. Get all customers who have placed at least one order.

139. Retrieve customers who haven't placed any orders.

140. Find orders where quantity is not in (1, 2, 3)

141. Retrieve all orders with a NULL customer ID (if any exist).

142. Retrieve all customers who are from Texas or California (assuming more data).
143. Find all orders where the product name starts with 'S'.

144. Get all customers with 'DAVIS' in their last name.

145. Retrieve products that contain 'VR' in their name.

146. Retrieve all customers whose first name contains 'A'.

147. Retrieve orders where the product name contains either 'LAPTOP' or 'HEADSET'.

148. Retrieve customers whose email contains their first name.

149. Find orders where the quantity is between 2 and 5.


150. Retrieve all customers whose first name is either 'JOHN' or 'JANE'.

151. Retrieve all orders where order date is exactly '10-MAY-22'.

152. Get all customers where last name does not contain 'N'.

153. Find all products with 'CARD' in the name.

154. Retrieve orders where the total price is higher than the average total price.

155. Retrieve customers whose CID is greater than 5.

156. Find all orders where total price is less than 500.
157. Retrieve customers whose city is not 'DALLAS'.

158. Find all products where quantity is greater than or equal to 3.

159. Get customers whose last name is not 'LEWIS'.

160. Retrieve orders where order date is before '01-JAN-22'.

161. Get all customers where email does not contain 'JOHN'.

162. Retrieve orders where the total price is exactly 199.99.


163. Find all orders where the quantity is greater than 5.

164. Get all orders where the total price is not equal to 799.99.

165. Retrieve customers whose city name is less than 7 characters long.

166. Find all orders where quantity is 1.

167. Get all products where product name is exactly 'PRINTER'.


168. Retrieve orders where total price is greater than 100 but less than 500.

169. Find customers whose CID is not equal to 10.

170. Retrieve orders where the quantity is not equal to 4.

171. Get customers whose first name is exactly 'LAURA'.

172. Find orders where quantity is at most 3.


173. Retrieve customers where email starts with 'MICHAEL'.

174. Get all orders where order date is later than '01-JAN-21'.

175. Retrieve customers whose CID is less than or equal to 5.

176. Find all products where quantity is less than or equal to 10.
177. Get all orders where order date is not '15-FEB-21'.

178. Retrieve customers whose email contains 'MARTINEZ'.

179. Get all orders where product name is 'MOUSE'.

180. Calculate the total cost of each order (quantity * total price per unit).

181. Find the remaining amount a customer needs to reach $1000 in total purchase.
182. Increase each order’s total price by 5% due to tax.

183. Show the discounted price (10% off) of all products.

184. Calculate the average total price for all orders.

185. Compute the difference between the highest and lowest order price.
186. Find orders where the quantity is an even number.

187. Display price per unit by dividing total price by quantity.

188. Multiply order quantity by 2 to estimate demand.

189. Show the percentage of total revenue each order contributes.


190. Combine first and last name of customers.

191. Display customer full name with email.

192. Show product name with its quantity.

193. Create a formatted order summary for each order.


194. Display customer city with a greeting.

195. Show customer details formatted as an email signature.

196. Generate a username using first name and last name in lowercase.
197. Create an invoice label with customer and order details.

198. Generate a product label combining name and price.

199. Format a shipping label with customer name and city.

200. Retrieve customers who have placed at least one order.

201. Find orders where the total price is greater than the average total price.
202. Retrieve orders where the quantity is greater than any order placed by customer ID 2.

203. Find customers who have never placed an order.

204. Retrieve the highest total price of any order.

205. Retrieve the smallest order quantity.

206. Get all orders where total price is less than all orders by customer ID 5.

207. Find customers who have ordered a specific product (e.g., 'LAPTOP').

208. Retrieve orders where the quantity matches the maximum quantity ordered.
209. Get orders where the total price is higher than at least one order by CID 3.

210. Retrieve all orders made by customers from 'LOS ANGELES’.

211. Get the most expensive order.

212. Find the cheapest product ordered.

213. Retrieve customers who have spent more than $500 in total.

214. Retrieve orders that match the average quantity ordered.

215. Find customers who placed more than 2 orders.

216. Retrieve products ordered by customer ID 1.


217. Retrieve customers who ordered a product with a total price greater than 200.

218. Find orders where the quantity is equal to the average quantity.

219. Retrieve all orders placed on the same day as the most recent order.

➔ Questions on Multi Row Functions, Group By and Having Clause.

220. Find the total revenue generated from all orders.

221. Calculate the average order value.

222. Count the total number of orders placed.

223. Find the highest total price of an order.

224. Retrieve the lowest quantity ordered.


225. Find the total number of unique customers who placed an order.

226. Calculate the total quantity of products sold.

227. Determine the average quantity per order.

228. Retrieve the most recent order date.

229. Find the earliest order placed in the system.

230. Find the total sales for each customer.

231. Show the average order value for each customer.


232. Retrieve the highest order value per customer.

233. Find the total quantity of products ordered by each customer.

234. Display the total revenue per product.

235. Calculate the average quantity ordered for each product.


236. Count the number of orders placed by each customer.

237. Find the total revenue for each city based on customer orders.

238. Retrieve the total number of customers per city.

239. Find customers who have spent more than $500 in total.

240. Retrieve products that generated more than $1000 in total sales.
241. Find cities where total customer spending is above $2000.

242. Display customers who have placed more than 3 orders.

243. Find product categories where the average order value is greater than $300.

➔ QUESTIONS ON CASE1, CASE2, CASE1 & CASE2, NESTED SUBQUERY


244. Find customers who have placed an order.

245. Retrieve products that have been ordered at least once.

246. Find customers from the city where the first order was placed.
247. Get the details of the most expensive product ordered.

248. Find orders where the total price is higher than the average total price.

249. Find customers who spent more than the average order value.

250. Retrieve products that cost more than the cheapest product ordered.

251. Find customers who have placed at least one order before a specific date.

252. List customers whose first order amount is more than the minimum order amount.
253. Find products that have been sold for more than their average price.

254. Get the order details for the highest total order price.

255. Find the customers whose total spending is greater than $500.

256. Find the product with the second highest price.

257. Find the average order value for each customer and display customers whose average order value is above
$200.

261. Retrieve customers whose total quantity of ordered products exceeds 10.
262. Find customers who have placed at least one order and are from a city where total spending is greater than
$5000.

263. Find customers who placed an order with the largest quantity.

264. Retrieve orders for the product with the lowest price.

265. Find customers who have spent more than the highest single order value.

266. Get the details of the customer who placed the first order.

267. Find products that were ordered by the customer who placed the highest quantity order.

268. List customers who have placed at least one order.

270. Retrieve customers who have never placed an order.


271. Find the total number of orders placed by each customer.

272. List customers and the total amount they have spent.

273. Find customers who have spent more than the average total spending of all customers.

274. Retrieve customers who placed an order in the last 6 months.


275. Find the most expensive product ordered.

276. List all products along with the customers who bought them.

277. Find customers who ordered both a "Laptop" and a "Smartphone".

278. Find products that have been ordered by more than one customer.

279. Find customers who ordered a product that costs more than the average product price.
280. Find customers who have never ordered a "Laptop".

281. Retrieve the most expensive order placed by each customer.

282. Find the number of products each customer has ordered.

283. Retrieve the most recent order for each customer.


284. Retrieve customers who placed orders on both weekdays and weekends.

285. List all products along with the number of unique customers who ordered them.

286. Retrieve the first order placed by each customer.

287. Find the total revenue generated from each city.


288. Retrieve customers whose total spending is within the top 10%.

289. Retrieve customers who have returned and placed a new order after at least 6 months of inactivity.

290. Find the percentage of total revenue contributed by each customer.

291. Retrieve customers who ordered a product with a price above the average.

292. List customers along with the number of different years they have placed orders in.
293. Retrieve customers who have ordered only during a specific year (e.g., 2022).

294. Find customers who have made a purchase in both the first and second half of the year.

➔ QUESTIONS ON INNER JOIN, SELF JOIN AND OUTER JOIN

295. Fetch customer names and product names they ordered.


296. List customers who have placed orders with total price above $500.

297. Retrieve customer emails and their corresponding order dates.

298. Fetch customers from 'New York' who have placed an order.

299. Retrieve all unique cities where customers have placed orders.
300. List customers who have purchased a 'LAPTOP'.

301. Fetch all orders placed on '05-JUL-23' along with customer details.

302. Retrieve the total number of orders placed by each customer.

303. List customers who have purchased more than one product.

304. Retrieve customer details along with the sum of their total purchases.
305. Find customers who have ordered both a 'LAPTOP' and a 'SMARTPHONE'.

306. List customers who have purchased exactly one product.

307. Find customers who have placed an order in 2023.

308. Retrieve customers who have placed an order for more than 2 items in a single order.

309. Find customers who have not purchased a 'VR HEADSET'.


310. Retrieve customers and their most expensive purchase.

311. Find the total revenue generated per city.

312. Find pairs of customers who live in the same city.

313. Retrieve pairs of customers who have the same last name.

314. Find customers who live in different cities but have the same first name.

315. Retrieve customers who have the same first letter in their first name.
316. Find customers who have similar names (first two letters match).

317. Retrieve customers who have the same last name but different first names.

318.Identify customers who have the same last two letters in their first names.

319. Retrieve customers who have not placed any orders.

320. Retrieve orders that do not belong to any registered customer.

321. Get all customers and the number of orders they placed (including those with no orders).
322. List all customers along with the most expensive product they purchased (if any).

323. Find customers who have placed an order for more than one product.

324. List customers who placed orders before they registered in the system.

325. Retrieve customers who have purchased more than one distinct product.
326. Retrieve customers along with the most expensive product they have purchased (if any).

327. Retrieve the system-generated row number for each customer.

328. Retrieve the current date and time from the system.

329. Fetch the unique row identifier for each order.


330. Get the username of the currently logged-in database user.

331. Retrieve customers sorted by their last names and assign a row number to each.

332. Retrieve the system-generated row ID for each customer in the CUSTOMER table.

333. Display the first and last customer IDs in the table.

334. Retrieve orders placed within the last 7 days using SYSDATE.
335. Retrieve the most recent order based on system-generated row numbers.

336. Get all customer details sorted by the latest added entry using ROWID.

➔ SOME OTHER CLAUSE USED FOR THE CREATION OF THE TABLE, DELETE, UPDATE ETC.

337. To create a table of customer with their associated attributes.

338. To create a table of prod_order table with their associated attributes and connection with the customer table.

339. Insertion of the records in the customer table which is created already.
340. Insertion of the records in the existing prod_order table.

341. Adding a Column.

342. Modifying a Column.

343. Dropping a Column.

344. Renaming a column.

345. Renaming a table.

346. To drop a column from the customer table.

347. To drop a table from the database.


DROP TABLE CUSTOMER;
348. To delete the table from the bin folder.
PURGE TABLE CUSTOMER;
349. To recover the deleted table from the bin.
FLASHBACK TABLE CUSTOMER
TO BEFORE DROP;
350. To delete the records from the table permanently.
TRUNCATE TABLE PROD_ORDER;
351. To modify a record in the existing table.
UPDATE CUSTOMER
SET FIRSTNAME = ‘ZANE’
WHERE CID = 2;
352. To remove a particular record from the existing table.
DELETE FROM CUSTOMER
WHERE FIRSTNAME= ‘DAVID’;

You might also like