Set an example, see if it fits:
create table tempVendas
(
DataVenda datetime,
FormaPagamento varchar(100)
)
insert into tempVendas values ('2018-01-01', 'Boleto')
insert into tempVendas values ('2018-01-01', 'Boleto')
insert into tempVendas values ('2018-01-01', 'Boleto')
insert into tempVendas values ('2018-01-01', 'Cartão')
insert into tempVendas values ('2018-01-01', 'Cartão')
insert into tempVendas values ('2018-02-01', 'Boleto')
insert into tempVendas values ('2018-02-01', 'Cartão')
insert into tempVendas values ('2018-02-01', 'Cartão')
insert into tempVendas values ('2018-02-01', 'Cartão')
insert into tempVendas values ('2018-03-01', 'Boleto')
insert into tempVendas values ('2018-03-01', 'Boleto')
insert into tempVendas values ('2018-03-01', 'Boleto')
insert into tempVendas values ('2018-03-01', 'Cartão')
insert into tempVendas values ('2018-03-01', 'Cartão')
insert into tempVendas values ('2018-03-01', 'Cartão')
insert into tempVendas values ('2018-03-01', 'Cartão')
insert into tempVendas values ('2018-03-01', 'Cartão')
SELECT month(dataVenda) [Mes],
count(case when FormaPagamento = 'Boleto' then FormaPagamento end) 'Boleto',
count(case when FormaPagamento = 'Cartão' then FormaPagamento end) 'Cartão',
count(FormaPagamento) Total
FROM tempVendas
group by month(dataVenda)
order by month(dataVenda)
http://sqlfiddle.com/#! 18/0c28a/2
What sales table structure? And how do you differentiate the form of payment?
– Jean Gustavo Prates
The structure of the sales table: Codvenda INT, Datavenda DATE, Valorvenda DECIMAL, Formapagamento INT. (Formapagamento 1 = Boleto, 2 = Cartão)
– D. Watson
Gabriel, this is relevant information that should be in the question. You can edit it and include =)
– Diego Rafael Souza