Row Results in Columns (SOMA)

0

Good afternoon, I have a big question in my query, I have a table with the following info:

Iwouldliketogetthefollowingresult

I need the result to be the total amount of (payment forms) per day, divided by period in two columns, M and N.

I think it's a very simple query, but I'm breaking my head and I'm not getting it. I've already tried using GROUP BY .

I found some tips on using PIVOT but I could not do SUM as this tool.

I got this query, but it is not what I want, it brings me the total of the day, not the total for the period I want.

My Query:

SELECT data, (SELECT format(SUM(valor),2,'de_DE') WHERE periodo = 'N') AS N, (SELECT format(SUM(valor),2,'de_DE') WHERE periodo = 'M') AS M FROM floja1 WHERE extract(month FROM data) = '05' GROUP BY data ORDER BY data

Thank you in advance.

Att; Danilo

    
asked by anonymous 12.06.2017 / 19:57

1 answer

0

Good night, Danillo. Try the following query:

select
    data,
    sum(if(periodo = 'M', valor, 0)) as 'M',
    sum(if(periodo = 'N', valor, 0)) as 'N'
from tabela
group by data
    
12.06.2017 / 23:50