Advertisement
vallec

Untitled

Apr 8th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /* 1 */
  2. DROP VIEW IF EXISTS coach_salary_info;
  3. CREATE VIEW coach_salary_info AS
  4. SELECT DISTINCT
  5. c.name AS coach_name,
  6. CONCAT(sg.id, ' - ', sg.location) AS group_info,
  7. s.name AS sport_name,
  8. YEAR(sp.dateOfPayment) AS year,
  9. MONTH(sp.dateOfPayment) AS month,
  10. sp.salaryAmount
  11. FROM
  12. salaryPayments sp
  13. JOIN
  14. coaches c ON sp.coach_id = c.id
  15. JOIN
  16. coach_work cw ON sp.coach_id = cw.coach_id
  17. JOIN
  18. sportGroups sg ON cw.group_id = sg.id
  19. JOIN
  20. sports s ON sg.sport_id = s.id
  21. WHERE
  22. YEAR(sp.dateOfPayment) = YEAR(NOW()) AND MONTH(sp.dateOfPayment) = MONTH(NOW());
  23.  
  24.  
  25. /* 2 */
  26. DELIMITER //
  27. DROP PROCEDURE IF EXISTS students_multiple_groups;
  28. CREATE PROCEDURE students_multiple_groups()
  29. BEGIN
  30. SELECT
  31. s.name AS student
  32. FROM
  33. students s
  34. JOIN
  35. student_sport ss ON s.id = ss.student_id
  36. GROUP BY
  37. ss.student_id
  38. HAVING
  39. COUNT(DISTINCT ss.sportGroup_id) > 1;
  40. END//
  41.  
  42. DELIMITER ;
  43. CALL students_multiple_groups();
  44.  
  45. /* 3 */
  46. DELIMITER //
  47. DROP PROCEDURE IF EXISTS coaches_no_groups;
  48. CREATE PROCEDURE coaches_no_groups()
  49. BEGIN
  50. SELECT
  51. c.name AS coach_name
  52. FROM
  53. coaches c
  54. LEFT JOIN
  55. coach_work cw ON c.id = cw.coach_id
  56. WHERE
  57. cw.coach_id IS NULL;
  58. END//
  59.  
  60. DELIMITER ;
  61.  
  62. CALL coaches_no_groups();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement