Using timestampdiff in a Derby WHERE clause

倾然丶 夕夏残阳落幕 提交于 2019-11-28 08:57:32

问题


I would like to simulate the effect of the following type of query (that is in Microsoft SQL Server syntax) in a Derby database. The goal is to return all records in the table where the date stored in "someColumn" is less than 7 days old. Here is the Microsoft SQL syntax for what I wish to achieve...

select * from someTable where datediff(dd, someColumn, getdate()) < 7

I have been able to determine that in Derby it will involve use of the timestampdiff function. But the syntax of the usage of functions in a WHERE clause in Derby is unknown to me and I cannot find any examples. I have found many examples where a function is used in the "what to return" clause, such as this...

select {fn timestampdiff(SQL_TSI_HOUR, startdate, enddate)} as diff

But I have not found an example of how to use such a function in a WHERE clause.

I acknowledge that my question is really "how do I use a function in a Derby WHERE clause", and yes, it's pretty basic. I also swear that I have really tried hard to find examples before posting. I hope someone can help.


回答1:


You can see an example in the original patch email,

SELECT * FROM t WHERE {fn TIMESTAMPDIFF( SQL_TSI_DAY, CURRENT_DAY, promisedDate)} <= 1


来源:https://stackoverflow.com/questions/11511805/using-timestampdiff-in-a-derby-where-clause

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!