我遇到查询问题。我需要获得一系列日期时间之间的所有记录。在日期时间范围内选择记录
我有以下几点:
select *
from db
where date between '2017-05-02 11:35:31.877' and '2017-05-02 17:06:24.727'
我试图与转换,采用铸造,即使< =和> =,但没有任何变化。
编辑
我想:在输出
select *
from db
where date between cast('2017-05-02 11:35:31.877' as datetime) and cast('2017-05-02 17:06:24.727' as datetime)
select *
from db
where date between convert(datetime,'2017-05-02 11:35:31.877') and convert(datetime,'2017-05-02 17:06:24.727')
select *
from db
where date >= '2017-05-02 11:35:31.877' and date <= '2017-05-02 17:06:24.727'
但绝对没有。我敢肯定,日期为datetime型
其实,我敢肯定有记录在表中
https://www.w3schools.com/sql/func_convert.asp – etsa
或发布您尝试过的内容,示例数据,输出和预期输出 – etsa
您能解释一下这个问题吗?你得到不正确的行吗?不够还是太多? “日期”列的数据类型是什么? –