How to add columns from values in a row?

3

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:


With the following query:

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;  

Can you get this table?

UPDATE 2 ##

Thanks to guido for informing me, now this resource is available to test:
page to test sql

    
asked by José L. 05.01.2018 в 20:35
source

2 answers

0

José Gonzáles of slack de proin chile found a solution: link
And Francisco Ignacio Contreras from the CL Programmers group, too:
sqlfiddle.com/#!9/9c1695/62
thank you very much everyone.

    
answered by 06.01.2018 / 19:23
source
1

use a pivot of the columns just fail to execute the string xd gives me an error but the basic idea is already link

    
answered by 06.01.2018 в 17:45