Advertisement
panaewboi

203

Nov 28th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. -1-
  3. Show all merchandiser id and merchandiser name that join after 15 June 2019 and have total cost more than 1000 Bath.
  4. .
  5. SELECT m.merchandiser_id, m.merchandiser_name, m.join_date, r.total_cost
  6. FROM merchandiser m
  7. JOIN receipt r
  8. ON m.merchandiser_id = r.merchandiser_id
  9. WHERE m.join_date > '15-JUN-2019'
  10. AND r.total_cost > 1000;
  11.  
  12.  
  13. -2-
  14. Show all data of promotion that are now available order by end date with descending order.
  15. .
  16. SELECT p.promotion_id, p.promotion_name, p.detail, p.start_date, p.end_date
  17. FROM promotion p
  18. WHERE SYSDATE >= p.start_date
  19. AND SYSDATE <= p.end_date
  20. ORDER BY p.end_date DESC;
  21.  
  22.  
  23. -3-
  24. show data of merchandiser owner whose age is under 25 years-old or live in Bangkok and be a man.
  25. .
  26. SELECT mo.*, EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM mo.date_of_birth) AS AGE
  27. FROM merchandiserowner mo
  28. JOIN merchandiserowneraddress moa
  29. ON moa.merchandiser_owner_id=mo.merchandiser_owner_id
  30. WHERE moa.province='Bangkok'
  31. AND mo.gender='M'
  32. AND EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM mo.date_of_birth) < 40
  33. ORDER BY mo.merchandiser_owner_id;
  34.  
  35.  
  36. -4-
  37. show all data of receipt product service which price is more than the avarage of all receipt product service price and be a product.
  38. .
  39. SELECT * FROM receiptproductservice r
  40. WHERE price >
  41. (SELECT AVG(price) FROM receiptproductservice
  42. WHERE r.receipt_id = receipt_id
  43. GROUP BY receipt_id
  44. )
  45. INTERSECT
  46. (SELECT * FROM receiptproductservice r
  47. WHERE r.product_service_type = 'product');
  48.  
  49.  
  50. -5-
  51. show data of all merchandiseowner that has exactly same last name and the differerenet in their age are not more than 5 years.
  52. .
  53. SELECT * FROM merchandiserowner mo1
  54. LEFT OUTER JOIN merchandiserowner mo2
  55. ON mo2.merchandiser_owner_id=mo1.merchandiser_owner_id
  56. WHERE mo1.last_name=mo2.last_name
  57. AND mo1.first_name<>mo2.first_name
  58. AND months_between(mo1.date_of_birth, mo1.date_of_birth)/12 Between -5 AND 5;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement