Untitled

mail@pastecode.io avatar
unknown
mysql
a year ago
572 B
2
Indexable
Never
SELECT 
    gender
  , name
FROM (
  SELECT
      gender
    , name
    , ROW_NUMBER() OVER (PARTITION BY gender ORDER BY cnt DESC) AS rn
  FROM (
    SELECT
        e.gender
      , s.name
      , count(1) AS cnt
    FROM Mentorship AS m
        JOIN Employee AS e
            ON m.student_id = e.id
              AND m.specialization_id = e.specialization_id
        JOIN Specialization AS s
            ON m.specialization_id = s.id
    WHERE m.start_date >= DATE_SUB(CUR_DATE(), INTERVAL 1 YEAR)
    GROUP BY e.gender, s.name
  )
)
WHERE rn = 1;