Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to query data by time period in SQL
How to query data by time period in SQL

sql server:

select * from table where occurrence date>'2008-7-1' and occurrence date<'2008-12-31'

access:

select * from table where occurrence date>#2008-7-1# and occurrence date<#2008-12-31#

This is enough, pay attention to sql server It is a little different from the date in access.

Extended information:

SQL query date statement

select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0? // Query the data for the first anniversary of today's date

select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0? //Query all data for the day

SELECT * FROM A where datediff(d,datetime,getdate()) <=30 //First 30 days

SELECT * FROM A WHERE DATEDIFF(m, shijian, GETDATE()) <=1? // ?Previous month

An alternative method to query the records of the current day:

SELECT *?

FROM j_GradeShop?

WHERE (GAddTime BETWEEN CONVERT (datetime, LEFT(GETDATE(), 10) + ' 00:00:00.000')?

AND CONVERT(datetime, LEFT(GETDATE(), 10) + ' 00:00:00.000') + 1)?

ORDER BY GAddTime DESC