0

I have a price column and a date column in an sql database which contains daily prices for the last 10 years. I want to be able get the price for the 1st of the month for each month in the table without providing a date.

All solutions so far have required me to provide a date such as this: How can I select the first day of a month in SQL?

I am fairly new to SQL and so am unsure of the code within the answer. Any help and explanation would be greatly appreciated.

Thanks

gerardcslabs
  • 213
  • 1
  • 3
  • 9

1 Answers1

2

One method uses simple filtering:

select t.*
from t
where extract(day from date) = 1;

Date functions are particularly database-dependent. EXTRACT() is standard SQL, but many databases use DAY() to extract the day of the month from the date.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786