sql server - SQL Last 6 Months -


i have table containing 1 datetime column. need return rows last 6 months. can done

where datetime_column > dateadd(m, -6, current_timestamp) 

but how extend option if want return latest month beginning first day of month? e.g. run condition in middle of month (14/6/2000), latest row set 14/1/2000, return 1/1/2000. advice?

i tried subqueries (max function of datetime including month function) no success.

for ms sql server, can use:

where datetime_column >= dateadd(month, datediff(month, 0, dateadd(m, -6, current_timestamp)), 0)


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -