I need to make an application that allows me to keep track of the results of Fishing and Hunting Competitions. For this problem I designed the following database:
I must generate the following table:
it is not possible to distinguish very well but the columns would be a number of ranking, the club, the scores, and the total of the scores.
And now I can show this:
SELECT concat(PE.nombre," ",PE.apellidoPaterno) as Nombre,
CL.nombre as Club,
SUM(PC.puntaje) as 'Puntaje Total'
from persona PE
join club CL
on CL.id_club=PE.id_club
join personacomp PC
on PE.id_persona=PC.id_persona
join competencia CO
on PC.id_competencia=CO.id_competencia
where PC.id_categoria=1
and year(CO.fecha)=2017
group by PE.id_persona;
Can the rows of the PersonaComp table scores be added to each person as columns to the above selection?
I am attentive to any questions, and feedback on the design of the database.
UPDATE ##
Now I can show the following table:
Using the following query:
SELECT concat(PE.nombre," ",PE.apellidoPaterno) as Nombre,
case when PC.id_competencia =1 THEN PC.puntaje END 'Puntaje 1' ,
case when PC.id_competencia =2 THEN PC.puntaje END 'Puntaje 2',
case when PC.id_competencia=3 THEN PC.puntaje END 'Puntaje 3'
from persona PE
join personacomp PC
on PE.id_persona=PC.id_persona
where PC.id_categoria=1;
UPDATE 2 ##
Thanks to guido for informing me, now this resource is available to test:
page to test sql