Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

sql - Using timestampdiff in a Derby WHERE clause

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can see an example in the original patch email,

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...