我有一个start_date和end_date。我想要得到这两个日期之间的日期列表。有人能帮我指出我的查询中的错误吗?

select Date,TotalAllowance 
from Calculation 
where EmployeeId=1
  and Date between 2011/02/25 and 2011/02/27

这里Date是一个datetime变量。


当前回答

SELECT CITY, COUNT(EID) OCCURENCES FROM EMP 
WHERE DOB BETWEEN '31-JAN-1900' AND '31-JAN-2900' 
GROUP BY CITY 
HAVING COUNT(EID) > 2;

该查询将查找DOB位于员工指定时间范围内的次数超过2次的城市。

其他回答

你可以试试这个SQL

select * from employee where rec_date between '2017-09-01' and '2017-09-11' 

实际上,为了得到最准确的结果,所有sql日期都应该是yyyy-MM-dd格式。

我会选择

select Date,TotalAllowance from Calculation where EmployeeId=1
             and Date >= '2011/02/25' and Date < DATEADD(d, 1, '2011/02/27')

逻辑是>=包括整个开始日期,<不包括结束日期,因此我们在结束日期上添加一个单位。这可以适应几个月,例如:

select Date, ... from ...
             where Date >= $start_month_day_1 and Date < DATEADD(m, 1, $end_month_day_1)
select Date,TotalAllowance 
from Calculation 
where EmployeeId=1
  and convert(varchar(10),Date,111) between '2011/02/25' and '2011/02/27'

我喜欢使用1 MonthName 2015语法来表示日期:

   WHERE aa.AuditDate>='1 September 2015'
     AND aa.AuditDate<='30 September 2015'

对日期