Total sales per month grouped by seller

Asked

Viewed 63 times

2

I need to bring a list of executives and total sales per month, all regardless of whether they sell in the month or not.

For years I am focused on front-end and I have never done anything with sql, can help me?

vendedor   janeiro fevereiro marco abril maio junho julho agosto ...

vendedor1  300     400       800   0     0    0     0     0
vendedor2  100     50        30    0     100  50    0     0
  • you can search for unpivot and group by.

1 answer

2


Good afternoon! Please let me know if the code works correctly. thank you.

SELECT 
sum(janeiro) AS total_jan,
sum(fevereiro) AS total_fev,
sum(marco) AS total_mar,
sum(abril) AS total_abr,
sum(maio) AS total_mai,
sum(junho) AS total_jun,
sum(julho) AS total_jul,
sum(agosto) AS total_ago,
sum(setembro) AS total_set,
sum(outubro) AS total_out,
sum(novembro) AS total_nov,
sum(dezembro) AS total_dez
FROM nome_da_tabela
GROUP BY vendedor;
  • Just yesterday, I sat down calmly, opened a beer and erased everything to think things through and it worked, yes it was in the same style as your code. I am very grateful for the answer.

  • 100sacional ! I’m glad it worked! We’re together ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.