DBMS Practice Questions PDF

Summary

This document is a collection of practice questions on SQL queries. The questions cover various aspects of database management systems, including queries for retrieving data, aggregations, and filtering. The database topics likely include tables and relationships.

Full Transcript

DBMS PRACTICE QUESTIONS 1. Fetch order number, total amount of purchase and average quantity ordered for the order number 10103 2. Fetch order number, total amount of purchase and average quantity ordered for each order number 3. Fetch the total average purchase for the order number 1010...

DBMS PRACTICE QUESTIONS 1. Fetch order number, total amount of purchase and average quantity ordered for the order number 10103 2. Fetch order number, total amount of purchase and average quantity ordered for each order number 3. Fetch the total average purchase for the order number 10103 4. Fetch the total average purchase for each order number 5. Fetch average quantity ordered 6. Fetch order number and quantity ordered who all are less than the average quantity order 7. Fetch order number and price each whose price is less than the average price for order number 10103 8. Fetch order number and price each whose price is less than the average price for each order 9. Fetch product code, Productname and total amount of purchase for the product code S10_1678, if all the stock is bought 10. Fetch product code and buy price where the buy price is between 50&100 11. Fetch the average buy price 12. Fetch product code and buy price whose buy price is greater than the average buy price 13. Fetch product code and the quantity in stock where the quantity in stock is less than the average quantity in stock 14. Fetch the total number of purchase for each order number (use order details table) 15. Fetch price for each order for order number 10100 16. Fetch the total purchase amount for order number 10100 17. Fetch the average total purchase amount for order number 10100 18. Fetch order number and average purchase amount for each order number 19. Fetch the quantity ordered and order number for the order number 10100 20. Fetch order number and average quantity ordered for order number 10100 21. Fetch order number and average quantity ordered for each customer 22. Fetch all the order number ,price whose price is greater than average price 23. Fetch all the details ftom product table 24. Fetch product name Ane product code from product's table 25. Fetch product name, product code and product line whose product code is S10_1678 26. Fetch unique product line from product table 27. Fetch count of unique product line from product's table 28. Fetch product vendor for classic cars 29. Fetch quantity in stock for the product 1968ford mustange 30. Fetch product name and buy price for the products where the buy price is not equal to 48.81 31. Find the count of products where the buy price is not equal to 48.81 32. Fetch product name and buy price where the buy price is between 50 and 100 33. Fetch product vendor and buy price, arrange product vendor in ascending order 34. Fetch product vendor and buy price,s arrange buy price in descending order 35. Fetch product vendor and buy price, arrange product vendor in descending order and buy price in ascending order 36. Fetch product name and product code where product code starts with S10 37. Fetch product code and product name where product name starts with 1969 38. Fetch product vendor where product line ends with cars 39. Fetch and Arrange product line in asc order and buy price in des order. 40. Fetch product name and quantity in stock, arrange product name in ascending and quantity in stock in descending 41. Fetch order number and price each from order details whose order number is 10100. 42. Fetch order number, order line number and price each from order details where order number is 10100 and order line number is 1 43. Fetch order number, order line number and price each from order details where order number is 10100 or order line number is 1 44. Fetch city and country from offices table where the country is US or France 45. Fetch city and country from offices table where the country is US and France 46. Fetch city and country from offices table where country is not USA 47. Fetch city and country from offices table where the country does not start with U 48. Fetch office code city and country from offices table where office code is not between 1-3 49. Fetch customer number, cheque number and amount from payments table, where customer number is between 101-110 50. Fetch customer number, cheque number and amount from payments table, where customer number is not between 101-110 51. Fetch customer number, cheque number and amount from payments table, where customer number is not between 110-200 52. Fetch customer number, cheque number and amount from payments table, where customer number is between 101-110. Arrange cheque number in descending order and amount in ascending order 53. Fetch customer number, cheque number and amount from payments table, where customer number is between 101-110. where cheque number ends with 515 54. Fetch customer number, cheque number and amount from payments table, where customer number is between 101-110. Arrange cheque number in descending order and amount in ascending order. Amount is 6607 55. Fetch Fetch customer number, cheque number and amount where the customer number is 114 56. Fetch product code and mini price form order details 57. Fetch product code, min price and max price from.order details 58. Fetch product code, mini and max price whose product code starts with S10 59. Fetch product code,minimum and maximum price for each product code 60. Fetch minimum and maximum quantity ordered for each product code 61. Find total number of quantity ordered 62. Find total number of quantity ordered and rename.the quantity as total quantity 63. Find order number and the total number of quantity ordered whose order number is 10100 64. Find order number , the total quantity ordered , rename.it as total quantity whose order number is 10100 65. Fetch order number and total quantity ordered for each order number 66. Fetch customer number and the count for the same in orders table 67. Fetch the number of comments in order section 68. Fetch the total number of status from orders table 69. Fetch the total number of shipped orders 70. Fetch the customer number and status of the order who all are shipped 71. Fetch the customer number, order date and the status for the orders who all are shipped 72. Fetch order number and total amount of orders for order number 10100 (order details table) 73. Fetch order number and total amount of orders for each order number 74. Fetch all the details for customers 75. Fetch customer number and customer name 76. Fetch cities from customer table 77. Fetch count of cities from customer table 78. Fetch unique cities from customer table 79. Fetch count of unique cities 80. Fetch customer number and customer name who all are from city Las Vegas 81. Fetch customer fname and number whose sales representative number is 1165 82. Fetch customer number and customer fname and lname whose Credit limit is 170300 83. Fetch name of the state whose postal code is 3004 84. Find customer name whose number is 103 85. Find total number of customers 86. Fetch the customer number and customer name whose customer number is less than 200 87. Find the count of the customers whose customer number is less than 200 88. Find the customer number and customer 89. name whose customer number is greater than 200 90. Find the count of customer whose customer number is greater than 200 91. Fetch first 20 records from payments table, after arranging the amount in descending order. 92. Fetch customer number, check number, date and amount from payments table, after arranging the payments date in descending fetch top 10 records 93. Fetch top 3 records of payments with customer number 114 94. Find the minimum payment amount from payments table 95. Find maximum payment value or maximum value from payments table 96. Fetch minimum payment Amount and give the title name as smallest purchase 97. Find the total number of payments 98. Fetch count of reporting persons in employees table 99. Fetch all the details of the table order details 100. Fetch the product code starts with S18 101. Fetch the order number and order line number where order line number is 1 102. Fetch minimum price per product 103. Fetch minimum price and give the title as smallest purchase amount 104. Fetch minimum and maximum product price 105. Fetch order number, product code, price each , where the order number is 10100 106. Fetch order number and maximum price each where the order number is 10100 107. Fetch order number and minimum price each where the order number is 10100 108. Fetch order number and respective minimum purchase price 109. Fetch order number and respective maximum purchase price 110. Fetch order number and maximum quantity order 111. Fetch order number and respective maximum quantity order 112. Find the number of orders for each order number CATEGORY WISE 1. WHERE Queries: 1. Fetch order number and price each whose price is less than the average price for order number 10103. 2. Fetch order number and price each whose price is less than the average price for each order. 3. Fetch product code and buy price where the buy price is between 50 & 100. 4. Fetch product name and buy price for the products where the buy price is not equal to 48.81. 5. Fetch product code and the quantity in stock where the quantity in stock is less than the average quantity in stock. 6. Fetch city and country from offices table where the country is US or France. 7. Fetch city and country from offices table where the country is US and France. 8. Fetch city and country from offices table where the country does not start with U. 9. Fetch city and country from offices table where country is not USA. 10. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110. 11. Fetch customer number, cheque number, and amount from payments table, where customer number is not between 101-110. 12. Fetch customer number, cheque number, and amount from payments table, where customer number is not between 110-200. 13. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110. Arrange cheque number in descending order and amount in ascending order. 14. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110 and where cheque number ends with 515. 15. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110, arrange cheque number in descending order and amount in ascending order. Amount is 6607. 16. Fetch product code and buy price whose buy price is greater than the average buy price. 17. Fetch customer number, cheque number, and amount where the customer number is 114. 18. Fetch product vendor for classic cars. 19. Fetch quantity in stock for the product 1968 ford mustang. 20. Fetch product vendor where product line ends with cars. 21. Fetch product vendor and buy price, arrange product vendor in ascending order. 22. Fetch product vendor and buy price, arrange buy price in descending order. 23. Fetch product vendor and buy price, arrange product vendor in descending order and buy price in ascending order. 24. Fetch order number and quantity ordered for those whose quantity is less than the average quantity. 25. Fetch order number, order line number, and price each from order details where order number is 10100 and order line number is 1. 26. Fetch order number, order line number, and price each from order details where order number is 10100 or order line number is 1. 27. Fetch order number and maximum price each where the order number is 10100. 28. Fetch order number and minimum price each where the order number is 10100. 29. Fetch order number and respective minimum purchase price. 30. Fetch order number and respective maximum purchase price. 31. Fetch order number and maximum quantity ordered. 32. Fetch order number and respective maximum quantity order. 33. Fetch order number and price each from order details whose order number is 10100. 34. Fetch product code and product name where product code starts with S10. 35. Fetch product code and product name where product name starts with 1969. 36. Fetch order number and product code, price each, where the order number is 10100. 37. Fetch order number and price whose price is greater than the average price. 38. Fetch office code, city, and country from offices table where office code is not between 1- 3. 39. Fetch first 20 records from payments table, after arranging the amount in descending order. 40. Fetch customer number, cheque number, date, and amount from payments table, after arranging the payments date in descending order, fetch top 10 records. 41. Fetch top 3 records of payments with customer number 114. 42. Fetch order number and maximum quantity order. 43. Fetch order number, product code, price each, where the order number is 10100. 44. Fetch customer number, cheque number, and amount where customer number is 114. 45. Fetch order number, product code, price each from order details where the order number is 10100. 46. Fetch customer first name and number whose sales representative number is 1165. 47. Fetch product name and product code where product code starts with S10. 48. Fetch product code starts with S18. 49. Fetch order number and order line number where order line number is 1. 50. Fetch order number and price each from order details where order number is 10100. 2. SUM / TOTAL Queries: 1. Fetch total amount of purchase for the order number 10103. 2. Fetch total amount of purchase for each order number. 3. Fetch the total average purchase for the order number 10103. 4. Fetch total average purchase for each order number. 5. Fetch total number of quantity ordered. 6. Find total number of payments. 7. Fetch total number of shipped orders. 8. Fetch order number and total amount of orders for order number 10100 (order details table). 9. Fetch order number and total amount of orders for each order number. 10. Fetch order number and total quantity ordered for each order number. 11. Find order number and total quantity ordered for order number 10100. 3. AVG (Average) Queries: 1. Fetch the total average purchase for the order number 10103. 2. Fetch total average purchase for each order number. 3. Fetch average quantity ordered. 4. Fetch the average total purchase amount for order number 10100. 5. Fetch order number and average purchase amount for each order number. 6. Fetch order number and average quantity ordered for the order number 10100. 7. Fetch order number and average quantity ordered for each customer. 8. Fetch the average buy price. 4. COUNT Queries: 1. Fetch count of unique product lines from the product's table. 2. Fetch count of cities from the customer table. 3. Fetch count of unique cities. 4. Find total number of customers. 5. Fetch count of reporting persons in employees table. 6. Find the count of customers whose customer number is less than 200. 7. Find the count of customers whose customer number is greater than 200. 8. Fetch the total number of status from orders table. 9. Fetch the number of comments in order section. 10. Fetch the total number of products whose buy price is not equal to 48.81. 5. SELECT / FETCH Queries: 1. Fetch all the details from product table. 2. Fetch product name and product code from product's table. 3. Fetch product code, Productname, and total amount of purchase for the product code S10_1678, if all the stock is bought. 4. Fetch customer number and customer name. 5. Fetch customer number and the count for the same in orders table. 6. Fetch all the details of the table order details. 7. Fetch product code and mini price from order details. 8. Fetch order number and the respective maximum purchase price. 9. Fetch order number and the respective minimum purchase price. 10. Fetch all the details for customers. 11. Fetch customer number and customer name. 6. MIN/MAX Queries: 1. Fetch minimum and maximum product price. 2. Fetch minimum and maximum product price for each product code. 3. Fetch the minimum payment amount from payments table. 4. Fetch maximum payment value or maximum value from payments table. 5. Fetch minimum payment amount and give the title name as smallest purchase. 6. Fetch minimum price per product. 7. Fetch minimum price and give the title as smallest purchase amount. 8. Fetch minimum and maximum product price. 9. Fetch product code, min price, and max price from order details. 10. Fetch product code, mini and max price whose product code starts with S10. 11. Fetch product code, minimum, and maximum price for each product code. 12. Fetch minimum and maximum quantity ordered for each product code. 13. 7. JOIN (Implied) Queries: 1. Fetch customer number and status of the order for shipped orders. 2. Fetch customer number, order date, and the status for the orders that are shipped. 3. Fetch customer number and customer name for customers from Las Vegas. 4. Fetch customer number and customer fname and lname whose Credit limit is 170300. 5. Find the customer name whose number is 103. 6. Fetch state name whose postal code is 3004. 8. SORT Queries: 1. Fetch product vendor and buy price, arrange product vendor in ascending order. 2. Fetch product vendor and buy price, arrange buy price in descending order. 3. Fetch product name and quantity in stock, arrange product name in ascending and quantity in stock in descending order. 4. Fetch city and country, arrange by ascending or descending based on conditions. 5. Fetch customer number and arrange cheque number in descending order and amount in ascending order. 6. Fetch customer number, cheque number, date, and amount from payments table, arrange payments by date in descending order. QUESTIONS WITH SOLUTIONS 1. Fetch order number, total amount of purchase and average quantity ordered for the order number 10103: SELECT orderNumber, SUM(priceEach * quantityOrdered) AS total_amount, AVG(quantityOrdered) AS average_quantity FROM orderdetails WHERE orderNumber = 10103; 2. Fetch order number, total amount of purchase and average quantity ordered for each order number: SELECT orderNumber, SUM(priceEach * quantityOrdered) AS total_amount, AVG(quantityOrdered) AS average_quantity FROM orderdetails GROUP BY orderNumber; 3. Fetch the total average purchase for the order number 10103: SELECT AVG(priceEach * quantityOrdered) AS average_purchase FROM orderdetails WHERE orderNumber = 10103; 4. Fetch the total average purchase for each order number: SELECT orderNumber, AVG(priceEach * quantityOrdered) AS average_purchase FROM orderdetails GROUP BY orderNumber; 5. Fetch average quantity ordered: SELECT AVG(quantityOrdered) AS average_quantity FROM orderdetails; 6. Fetch order number and quantity ordered who all are less than the average quantity order: SELECT orderNumber, quantityOrdered FROM orderdetails WHERE quantityOrdered < (SELECT AVG(quantityOrdered) FROM orderdetails); 7. Fetch order number and price each whose price is less than the average price for order number 10103: SELECT orderNumber, priceEach FROM orderdetails WHERE orderNumber = 10103 AND priceEach < (SELECT AVG(priceEach) FROM orderdetails WHERE orderNumber = 10103); 8. Fetch order number and price each whose price is less than the average price for each order: SELECT orderNumber, priceEach FROM orderdetails WHERE priceEach < (SELECT AVG(priceEach) FROM orderdetails WHERE orderdetails.orderNumber = orderNumber); 9. Fetch product code, Productname and total amount of purchase for the product code S10_1678, if all the stock is bought: SELECT productCode, productName, quantityInStock * buyPrice AS total_purchase FROM products WHERE productCode = 'S10_1678'; 10. Fetch product code and buy price where the buy price is between 50 & 100: SELECT productCode, buyPrice FROM products WHERE buyPrice BETWEEN 50 AND 100; 11. Fetch the average buy price: SELECT AVG(buyPrice) AS average_buy_price FROM products; 12. Fetch product code and buy price whose buy price is greater than the average buy price: SELECT productCode, buyPrice FROM products WHERE buyPrice > (SELECT AVG(buyPrice) FROM products); 13. Fetch product code and the quantity in stock where the quantity in stock is less than the average quantity in stock: SELECT productCode, quantityInStock FROM products WHERE quantityInStock < (SELECT AVG(quantityInStock) FROM products); 14. Fetch the total number of purchase for each order number (use order details table): SELECT orderNumber, SUM(quantityOrdered) AS total_purchase FROM orderdetails GROUP BY orderNumber; 15. Fetch price for each order for order number 10100: SELECT orderNumber, priceEach FROM orderdetails WHERE orderNumber = 10100; 16. Fetch the total purchase amount for order number 10100: SELECT orderNumber, SUM(priceEach * quantityOrdered) AS total_purchase FROM orderdetails WHERE orderNumber = 10100; 17. Fetch the average total purchase amount for order number 10100: SELECT AVG(priceEach * quantityOrdered) AS average_purchase FROM orderdetails WHERE orderNumber = 10100; 18. Fetch order number and average purchase amount for each order number: SELECT orderNumber, AVG(priceEach * quantityOrdered) AS average_purchase FROM orderdetails GROUP BY orderNumber; 19. Fetch the quantity ordered and order number for the order number 10100: SELECT orderNumber, quantityOrdered FROM orderdetails WHERE orderNumber = 10100; 20. Fetch order number and average quantity ordered for order number 10100: SELECT orderNumber, AVG(quantityOrdered) AS average_quantity FROM orderdetails WHERE orderNumber = 10100; 21. Fetch order number and average quantity ordered for each customer: SELECT orderNumber, AVG(quantityOrdered) AS average_quantity FROM orderdetails GROUP BY orderNumber; 22. Fetch all the order numbers and prices whose price is greater than the average price: SELECT orderNumber, priceEach FROM orderdetails WHERE priceEach > (SELECT AVG(priceEach) FROM orderdetails); 49. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber BETWEEN 101 AND 110; 50. Fetch customer number, cheque number, and amount from payments table, where customer number is not between 101-110 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber NOT BETWEEN 101 AND 110; 51. Fetch customer number, cheque number, and amount from payments table, where customer number is not between 110-200 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber NOT BETWEEN 110 AND 200; 52. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110. Arrange cheque number in descending order and amount in ascending order Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber BETWEEN 101 AND 110 ORDER BY checkNumber DESC, amount ASC; 53. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110. where cheque number ends with 515 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber BETWEEN 101 AND 110 AND checkNumber LIKE '%515'; 54. Fetch customer number, cheque number, and amount from payments table, where customer number is between 101-110. Arrange cheque number in descending order and amount in ascending order. Amount is 6607 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber BETWEEN 101 AND 110 AND amount = 6607 ORDER BY checkNumber DESC, amount ASC; 55. Fetch customer number, cheque number, and amount where the customer number is 114 Solution: SELECT customerNumber, checkNumber, amount FROM payments WHERE customerNumber = 114; 56. Fetch product code and mini price from order details Solution: SELECT productCode, MIN(priceEach) AS miniPrice FROM orderdetails; 57. Fetch product code, min price and max price from order details Solution: SELECT productCode, MIN(priceEach) AS minPrice, MAX(priceEach) AS maxPrice FROM orderdetails; 58. Fetch product code, mini and max price whose product code starts with S10 Solution: SELECT productCode, MIN(priceEach) AS miniPrice, MAX(priceEach) AS maxPrice FROM orderdetails WHERE productCode LIKE 'S10%'; 59. Fetch product code, minimum and maximum price for each product code Solution: SELECT productCode, MIN(priceEach) AS minPrice, MAX(priceEach) AS maxPrice FROM orderdetails GROUP BY productCode; 60. Fetch minimum and maximum quantity ordered for each product code Solution: SELECT productCode, MIN(quantityOrdered) AS minQuantity, MAX(quantityOrdered) AS maxQuantity FROM orderdetails GROUP BY productCode; 61. Find total number of quantity ordered: Solution: SELECT SUM(quantityOrdered) FROM orderdetails; 62. Find total number of quantity ordered and rename the quantity as total quantity: Solution: SELECT SUM(quantityOrdered) AS totalQuantity FROM orderdetails; 63. Find order number and the total number of quantity ordered whose order number is 10100: Solution: SELECT orderNumber, SUM(quantityOrdered) AS totalQuantity FROM orderdetails WHERE orderNumber = 10100 GROUP BY orderNumber; 64. Find order number, the total quantity ordered, rename it as total quantity whose order number is 10100: Solution: SELECT orderNumber, SUM(quantityOrdered) AS totalQuantity FROM orderdetails WHERE orderNumber = 10100 GROUP BY orderNumber; 65. Fetch order number and total quantity ordered for each order number: Solution: SELECT orderNumber, SUM(quantityOrdered) AS totalQuantity FROM orderdetails GROUP BY orderNumber; 66. Fetch customer number and the count for the same in orders table: Solution: SELECT customerNumber, COUNT(orderNumber) FROM orders GROUP BY customerNumber; 67. Fetch the number of comments in order section: Solution: SELECT COUNT(comments) FROM orders; 68. Fetch the total number of statuses from orders table: Solution: SELECT COUNT(DISTINCT status) FROM orders; 69. Fetch the total number of shipped orders: Solution: SELECT COUNT(*) FROM orders WHERE status = 'Shipped'; 70. Fetch the customer number and status of the order who all are shipped: Solution: SELECT customerNumber, status FROM orders WHERE status = 'Shipped'; 71. Fetch the customer number, order date and the status for the orders who all are shipped: Solution: SELECT customerNumber, orderDate, status FROM orders WHERE status = 'Shipped'; 72. Fetch order number and total amount of orders for order number 10100 (order details table): Solution: SELECT orderNumber, SUM(priceEach * quantityOrdered) AS totalAmount FROM orderdetails WHERE orderNumber = 10100 GROUP BY orderNumber; 73. Fetch order number and total amount of orders for each order number: Solution: SELECT orderNumber, SUM(priceEach * quantityOrdered) AS totalAmount FROM orderdetails GROUP BY orderNumber; 74. Fetch all the details for customers: Solution: SELECT * FROM customers; 75. Fetch customer number and customer name: Solution: SELECT customerNumber, customerName FROM customers; 76. Fetch cities from customer table: Solution: SELECT city FROM customers; 77. Fetch count of cities from customer table: Solution: SELECT COUNT(city) FROM customers; 78. Fetch unique cities from customer table: Solution: SELECT DISTINCT city FROM customers; 79. Fetch count of unique cities: Solution: SELECT COUNT(DISTINCT city) FROM customers; 80. Fetch customer number and customer name who all are from city Las Vegas: Solution: SELECT customerNumber, customerName FROM customers WHERE city = 'Las Vegas'; 81. Fetch customer fname and number whose sales representative number is 1165: Solution: SELECT customerNumber, contactFirstName FROM customers WHERE salesRepEmployeeNumber = 1165; 82. Fetch customer number and customer fname and lname whose Credit limit is 170300: Solution: SELECT customerNumber, contactFirstName, contactLastName FROM customers WHERE creditLimit = 170300; 83. Fetch name of the state whose postal code is 3004: Solution: SELECT state FROM customers WHERE postalCode = 3004; 84. Find customer name whose number is 103: Solution: SELECT customerName FROM customers WHERE customerNumber = 103; 85. Find total number of customers: Solution: SELECT COUNT(*) FROM customers; 86. Fetch the customer number and customer name whose customer number is less than 200: Solution: SELECT customerNumber, customerName FROM customers WHERE customerNumber < 200; 87. Find the count of the customers whose customer number is less than 200: Solution: SELECT COUNT(*) FROM customers WHERE customerNumber < 200; 88. Find the customer number and customer name whose customer number is greater than 200: Solution: SELECT customerNumber, customerName FROM customers WHERE customerNumber > 200; 89. Find the count of customer whose customer number is greater than 200: Solution: SELECT COUNT(*) FROM customers WHERE customerNumber > 200; 90. Fetch first 20 records from payments table, after arranging the amount in descending order: Solution: SELECT * FROM payments ORDER BY amount DESC LIMIT 20; 91. Fetch customer number, check number, date and amount from payments table, after arranging the payments date in descending fetch top 10 records: Solution: SELECT customerNumber, checkNumber, paymentDate, amount FROM payments ORDER BY paymentDate DESC LIMIT 10; 92. Fetch top 3 records of payments with customer number 114: Solution: SELECT * FROM payments WHERE customerNumber = 114 LIMIT 3; 93. Find the minimum payment amount from payments table: Solution: SELECT MIN(amount) FROM payments; 94. Find maximum payment value or maximum value from payments table: Solution: SELECT MAX(amount) FROM payments; 95. Fetch minimum payment amount and give the title name as smallest purchase: Solution: SELECT MIN(amount) AS smallestPurchase FROM payments; 96. Find the total number of payments: Solution: SELECT COUNT(*) FROM payments; 97. Fetch count of reporting persons in employees table: Solution: SELECT COUNT(reportsTo) FROM employees WHERE reportsTo IS NOT NULL; 98. Fetch all the details of the table order details: Solution: SELECT * FROM orderdetails; 99. Fetch the product code starts with S18: Solution: SELECT * FROM products WHERE productCode LIKE 'S18%'; 100. Fetch the order number and order line number where order line number is 1: Solution: SELECT orderNumber, orderLineNumber FROM orderdetails WHERE orderLineNumber = 1; 101. SELECT product_code, MIN(price_each) AS minimum_price FROM order_details GROUP BY product_code; 102. SELECT MIN(price_each) AS smallest_purchase_amount FROM order_details; 103. SELECT MIN(price_each) AS minimum_price, MAX(price_each) AS maximum_price FROM order_details; 104. SELECT order_number, product_code, price_each FROM order_details WHERE order_number = 10100; 105. SELECT order_number, MAX(price_each) AS maximum_price FROM order_details WHERE order_number = 10100 GROUP BY order_number; 106. SELECT order_number, MIN(price_each) AS minimum_price FROM order_details WHERE order_number = 10100 GROUP BY order_number; 107. SELECT order_number, MIN(price_each) AS minimum_purchase_price FROM order_details GROUP BY order_number; 108. SELECT order_number, MAX(price_each) AS maximum_purchase_price FROM order_details GROUP BY order_number; 109. SELECT order_number, MAX(price_each) AS maximum_purchase_price FROM order_details GROUP BY order_number; 110. SELECT order_number, MAX(quantity_ordered) AS maximum_quantity_ordered FROM order_details GROUP BY order_number; 111. SELECT order_number, MAX(quantity_ordered) AS maximum_quantity_ordered FROM order_details GROUP BY order_number; 112. SELECT order_number, COUNT(*) AS number_of_orders FROM order_details GROUP BY order_number;

Use Quizgecko on...
Browser
Browser