sqlmysqlselectstored-procedures

MySQL select title and columns


I have this output:

SELECT Arquivo, Safra, LinhasA FROM t411 LIMIT 10;

enter image description here

I would like to get this kind of output:

enter image description here

Is there any way directly using SELECT?

... can also be by PROCEDURE if necessary.

I would really appreciate it if anyone can help. I use MySQL Server (latest version) and run my selects through MySQL Workbench


Solution

  • I don't understand why you used limit 10 but, Can you try this?

    select
    Arquivo,
    max(case when Safra = '2019/2020' then LinhasA else 0 end) as '2019/2020',
    max(case when Safra = '2020/2021' then LinhasA else 0 end) as '2020/2021',
    max(case when Safra = '2021/2022' then LinhasA ELSE 0 end) as '2021/2022'
    from t411
    group by 1;