在Mysql中,Hi必须是当前年份的第一个日期和最后一个日期。
如何在MySql的where子句中找到?

SET NOCOUNT ON
DECLARE @MonthStartDate As datetime
DECLARE @MonthEndDate As datetime
DECLARE @today datetime
SELECT @today = convert(varchar(12) , getdate() , 101)

 SET @MonthStartDate = @today
 SELECT @MonthStartDate = dateadd ( dd , - datepart ( dd , @MonthStartDate ) ,
 @MonthStartDate+1 )
 SELECT @MonthEndDate = dateadd(dd , -1 , dateadd ( mm , +1 , @MonthStartDate))
 SELECT @MonthStartDate AS StartDate , @MonthEndDate AS EndDate

最佳答案

在子句之间使用
喜欢

select * from `table_name` where datetime_column as date between '01/01/2009' and curdate()

09-27 10:25