rootUser

SubQuery (extra-1)

Feb 8th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.58 KB | None | 0 0
  1. 1.WRITE a query TO find the name AND numbers OF ALL salesmen who had more than one customer.
  2.  
  3. SELECT name,salesman_id FROM salesman WHERE salesman_id IN
  4. (SELECT salesman_id FROM Customer GROUP BY salesman_id HAVING COUNT(salesman_id)>1)
  5.  
  6.  
  7. SELECT * FROM Customer
  8.  
  9. 2.WRITE a query TO counts the customers WITH grades above NEW York''s average
  10.  
  11. SELECT COUNT(customer_id) FROM Customer WHERE
  12. grade >(SELECT avg(grade) FROM Customer WHERE city= 'New York')
  13.  
  14.  
  15. 3.WRITE a query TO display ALL the orders which VALUES are greater than
  16. the average ORDER VALUE FOR 10th October 2012
  17.  
  18. SELECT ord_no FROM Orders WHERE purch_amt>
  19. (SELECT avg(purch_amt) FROM Orders WHERE ord_date ='2012-10-10')
  20.  
  21.  
  22. 4.WRITE a query TO find ALL orders attributed TO a salesman IN NEW york
  23.  
  24. SELECT ord_no FROM Orders WHERE salesman_id =
  25. (SELECT salesman_id FROM salesman WHERE city = 'New York' )
  26.  
  27.  
  28. 5.WRITE a query TO find the sums OF the amounts FROM the orders TABLE, grouped BY DATE,
  29.   eliminating ALL those dates WHERE the SUM was NOT at least 1000.00 above the maximum amount
  30.   FOR that DATE.
  31.  
  32.  
  33. SELECT SUM(purch_amt) AS Total FROM Orders
  34. GROUP BY ord_date HAVING ord_date IN
  35. (SELECT ord_date FROM Orders GROUP BY ord_date
  36. HAVING SUM(purch_amt)-1000 > MAX(purch_amt))
  37.  
  38.  
  39. ---------------------------------------------------------------------
  40.  
  41.  SELECT ord_date , purch_amt FROM Orders
  42.  
  43.  SELECT ord_date,SUM(purch_amt) AS total FROM Orders GROUP BY ord_date
  44.  
  45.   SELECT ord_date,MAX(purch_amt) AS maximum FROM Orders GROUP BY ord_date
  46.  
  47.  (SELECT ord_date FROM Orders GROUP BY ord_date HAVING SUM(purch_amt) >
Add Comment
Please, Sign In to add comment