SQL Server: Get data for only the past year

后端 未结 12 841
不思量自难忘°
不思量自难忘° 2020-12-12 17:09

I am writing a query in which I have to get the data for only the last year. What is the best way to do this?

SELECT ... FROM ... WHERE date > \'8/27/2007         


        
12条回答
  •  既然无缘
    2020-12-12 17:38

    The other suggestions are good if you have "SQL only".

    However I suggest, that - if possible - you calculate the date in your program and insert it as string in the SQL query.

    At least for for big tables (i.e. several million rows, maybe combined with joins) that will give you a considerable speed improvement as the optimizer can work with that much better.

提交回复
热议问题