2.9.sql 530 Bytes
Newer Older
Matias Ferreira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*2.9. Hacer un query que liste los alumnos que están morosos en todos los cursos en los que están inscriptos.*/

SELECT DISTINCT fullname
FROM
(
  SELECT *
  FROM enrollments
  WHERE student_iid IN
  (
    SELECT *
    FROM
    (
      SELECT student_iid st_id
      FROM enrollments
      GROUP BY student_iid, paid
      ORDER BY st_id
    )
    AS first
    GROUP BY first.st_id
    HAVING count(first.st_id) = 1
  )
  AND paid = 'false'
)
AS elegidos
  LEFT JOIN
    students st
ON elegidos.student_iid = st.student_iid  ;