问题:如何在where子句中使用当前时间
我想到了一个问题。是否有可能使用当前时间戳而不是Where子句中的选定日期?
SELECT this, that
FROM here
WHERE start>='2010-07-01'
我以为这会是……。例如:start='now()' 或 curdate() 或 curtime()。 我发现它们在 Select 子句中使用,但我在Where 中需要它。
非常感谢任何帮助。 弗洛拉
there was a question coming up to my mind. Is there any possibility to use the current timestamp instead of a selected date in the Where Clause?
SELECT this, that
FROM here
WHERE start>='2010-07-01'
I thought it would be sth. like: start='now()' or curdate() or curtime().
Anything I found was that they're used in the Select Clause, but I need it in Where.
Any help is much appreciated.
Flora
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以根据您的要求使用以下三个函数中的任何一个:
此查询的输出是 -
已编辑:
您可以按照指示在Where子句中使用这些函数。
You can use any of the following three functions as per your requirements:
The output of this query is -
Edited:
you can use these functions in Where clause as instructed.
当然可以:
您可以在
WHERE
子句中使用任何表达式,使用任何 内置日期和时间函数。Sure you can:
You can use any expression in the
WHERE
clause, using any inbuilt Date-and-Time function.我会使用
Just 因为这应该适用于每个 DBMS。但不知道 NOW() ,也许这是一个标准函数?
更新:现在我知道 NOW() 至少在 Oracle 中不起作用,所以我肯定会使用 current_timestamp、current_date 等,因为这些是标准中的。我已经完成了几次 DBMS 迁移(DB2 -> MySQL、MySQL -> Oracle 等),我很高兴我们尽可能使用符合标准的 SQL,这使得迁移相对轻松。
I'd use
Just because this should work in every DBMS. Don't know about NOW() though, maybe that's a standard function?
Update: well now I know NOW() does not work at least in Oracle, so I'd definitely go with current_timestamp, current_date etc, because these are in the standard. I've done a couple of DBMS migrations (DB2 -> MySQL, MySQL -> Oracle etc) and I'm glad we used the standards -compliant SQL where ever possible, which made the migrations relatively painless.
您不应该引用函数名称
使用如下所示的函数名称:
SELECT this, that FROM here WHERE
start >= NOW();
从这里选择这个,那个
start >= CURRENT_DATE();
You shouldn't to quote a function name
Use function names like this:
SELECT this, that FROM here WHERE
start >= NOW();
SELECT this, that FROM here WHERE
start >= CURRENT_DATE();