This exercise was presented to me:
Show students who have enrolled in more courses than Antoine de Saint-Exupery. Show all the data of the students, the number of courses to which they enrolled and how many times more than Juan Perez.
The tables present are:
Students
'dni'
'nombre'
'apellido'
'tel'
'email'
'direccion'
Registrations
'nom_plan'
'nro_curso'
'dni'
'fecha_inscripcion'
Courses
'nom_plan'
'nro_curso'
'fecha_ini'
'fecha_fin'
'salon'
'cupo'
What I did is this:
select alu.'dni', alu.'nombre', alu.'apellido', alu.'direccion', alu.'email',
alu.'tel', count(*)
from alumnos alu
inner join inscripciones insc
on alu.'dni' = insc.'dni'
inner join cursos cur
on cur.'nro_curso' = insc.'nro_curso'
group by 1
And what I would miss is the part of the subquery that would do it with a HAVING as well as the other count where they are shown how many times more than Juan Perez were registered, but they tell me to do it with variables or temporary tables. And I really do not understand how to do it, someone to help me? Thanks!