Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. 1. The company owner needs to know how many customers are from each state. Make a list of the customers by providing the state and the number of customers.
  2.  
  3. select state, COUNT(*)
  4. from customer
  5. group by state
  6.  
  7. 2. Modify the above query to sort the answer by count.
  8.  
  9. select state, COUNT(*) as 'Name'
  10. from customer
  11. group by state
  12. order by Name
  13.  
  14. select state, COUNT(*)
  15. from customer
  16. group by state
  17. order by 2
  18.  
  19. 3. Display the total number of catalogs of each manufacturer.
  20.  
  21. select manu_code, COUNT(*)
  22. from catalog
  23. group by manu_code
  24. order by 2
  25.  
  26. 4. Find the total shipping charge of every customer. Display the customer number and the amount. The report should display the highest amount first.
  27.  
  28. select customer_num, sum(ship_charge)
  29. from orders
  30. group by customer_num
  31. order by 2 desc
  32.  
  33. 5. List down the details of the customers who have placed more than 1 order.
  34.  
  35. select customer_num, COUNT(order_num)
  36. from orders
  37. group by customer_num
  38.  
  39. select customer_num, COUNT(order_num)
  40. from orders
  41. group by customer_num
  42. having COUNT(order_num)>1
  43.  
  44. 6. Modify the query of the question 3 to display the manufacturers who are having more than 1 catalog. The list should be sorted according to the manufacturer code.
  45.  
  46. select manu_code, COUNT(*)
  47. from catalog
  48. group by manu_code
  49. having COUNT(*)>1
  50.  
  51. 7. List down the total ship weights per customer order. The list should contain the order number, customer number and the total weight and sorted according to the customer number.
  52.  
  53. select customer_num, order_num, SUM(ship_weight)
  54. from orders
  55. group by customer_num
  56. order by customer_num
  57.  
  58. ^^ aggregate error
  59.  
  60. select customer_num, order_num, SUM(ship_weight)
  61. from orders
  62. group by customer_num, order_num
  63. order by customer_num
  64.  
  65. select customer_num, SUM(ship_weight)
  66. from orders
  67. group by customer_num
  68. order by customer_num
  69.  
  70. ^^ Correct one
  71.  
  72. 8. Find how many customers are there in each state with ‘Sport’ word included in the company name. Display the state and the number of customers.
  73.  
  74. select state, COUNT(*)
  75. from customer
  76. where company like '%sport%'
  77. group by state
  78.  
  79. select state, COUNT(*)
  80. from customer
  81. where company like '%sport%'
  82. group by state
  83. having COUNT(*)> 5
  84.  
  85. Having only works after grouping
  86.  
  87. 9. Find the total number of calls of every customer.
  88.  
  89. select COUNT(*)
  90. from cust_calls
  91.  
  92. 10. Display the manufacturer details of the manufacturer who is manufactured highest quantity of items.
  93.  
  94. select manu_code,MAX(quantity)
  95. from items
  96. group by manu_code
  97. order by 2 desc
  98.  
  99. 11. Display the average lead time of each manufacturer.
  100.  
  101. select AVG(lead_time)
  102. from manufact
  103.  
  104. 12. Find the customer who spent more than Rs. 5000 for shipping charges.
  105.  
  106. select customer_num
  107. from orders
  108. where ship_charge > 5000.00
  109.  
  110. 13. List down the order numbers of the orders which contain less than 200kg ship weight.
  111.  
  112. select *
  113. from orders
  114. where ship_weight > 200.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement