如何排除 BETWEEN sql server 中的上限
我使用 SQL Server 作为我的数据库。我正在搜索我输入的日期的行。这意味着搜索 submission_date
恰好是 '12/13/2011'
的行。首先,我将搜索条件日期转换为毫秒
,即
Dec 13 2011 00:00:00 ='1323727200000'
Dec 14 2011 00:00:00 ='1323813600000'`
SELECT *
FROM log_file
WHERE submission_date BETWEEN '1323727200000' AND '1323813600000'
此查询将搜索 Dec 13 Midnight
到 Dec 14 Midnight
,但我想跳过上限值,即从 <代码>2011年12月13日00:00:00到2011年12月13日59:59:59
。为此,我想使用 >= 和 <
。这是正确的做法吗?
完成此操作后,我有一个 iBatis xml,其中我正在编写以下内容,这给了我错误。
<isNotEmpty prepend="AND" property="submissiondate">
submission_date <![CDATA[ >= ]]> #submissiondate # AND <![CDATA[ < ]]> #submissiondate #
</isNotEmpty>
请建议这是否是正确的方法。
谢谢
I am using SQL Server as my database. I am searching for a row for the date that I have entered. This means searching rows where submission_date
is exactly '12/13/2011'
. First I am converting the search criteria date to milliseconds
i.e.
Dec 13 2011 00:00:00 ='1323727200000'
Dec 14 2011 00:00:00 ='1323813600000'`
SELECT *
FROM log_file
WHERE submission_date BETWEEN '1323727200000' AND '1323813600000'
This query will search for Dec 13 Midnight
to Dec 14 Midnight
, but I want to skip the upper limit value i.e. from Dec 13 2011 00:00:00
to Dec 13 2011 59:59:59
. For this I thought to use >= and <
. Is this a right approach?
Having done this, I have a iBatis xml where I am writing the following which is giving me error.
<isNotEmpty prepend="AND" property="submissiondate">
submission_date <![CDATA[ >= ]]> #submissiondate # AND <![CDATA[ < ]]> #submissiondate #
</isNotEmpty>
Please suggest if this is the right approach.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您通常会使用
>=
和<
进行时间/日期范围查询。或者,您可以从上限中减去 3 毫秒以获得最高日期时间 (不是较新的 datetime2) 当天的值 (
xxx 23:59.59.997
)注意:如果一切都是毫秒,则减去 1 可能就可以了...
编辑,为什么 3ms 的示例
以及有趣的是,你确定现在是午夜吗?
在 1323813600 秒内,我得到
2011-12-13 22:00:00
On SQL Server:
On MySQL
Yes, you'd use
>=
and<
typically for time/date range queriesAlternatively, you could subtract 3 milliseconds from the upper limit to get the highest datetime (not newer datetime2) value for that day (
xxx 23:59.59.997
)Note: subtracting 1 would probably be OK if everything is milliseconds...
Edit, example of why 3ms
And interestingly, are you sure this is midnight?
For 1323813600 seconds, I get
2011-12-13 22:00:00
On SQL Server:
On MySQL
在您的情况下,“日期”似乎是
BIGINT
类型,为什么不直接从间隔上限中减去 1 呢?当然,这不适用于浮点数或小数......
In your case, where "date" seems to be of type
BIGINT
, why not just subtract 1 from the upper interval limit?Of course, this wouldn't work with floating point numbers or decimals...
是的,如果您必须跳过上限 - 您应该使用
当然 - 如果您的列的类型是 DATETIME
Yes, if you have to skip the upper limit - you should use
Of course - if your column's type is DATETIME