Select a date field by extracting only the month and year

Asked

Viewed 27 times

0

I need to mount a Query that selects the sum of the vacant amount of each month in a period of one year.

In case there would be several dates within each month that would have vacancies, which should all be grouped in a given month.

SELECT Periodo, SUM(Quantidade) FROM Vagas
 WHERE Periodo between DATEPART(MONTH, '2019-02-01') and DATEPART(MONTH, '2019-07-31') 
 order by Periodo, Quantidade;

1 answer

0

SELECT year (Periodo) as Ano, month (Periodo) as [Mês],
       sum (Quantidade) 
  from Vagas 
  where Periodo >= '20190201'
        and Periodo < '20190801'
  group by year (Periodo), month (Periodo)
  order by Ano, Mes;

Browser other questions tagged

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