开发者

How do I know if a date is within the certain period

We are capturing attendance data in a certain table primarily capturing the values (userId, startDate, endDate). If a person applies leave on a certain date then only startDate is filled and if he applies for a set of dates then the start/end dates are captured. What query will help me find if a person is taking leave on a certain date (say on the 9th, 12th, 15th of this month)

user1, 9/8/2010
user2, 9/9/2010, 9/10/2010
user3, 9/14/2010
user4, 9/15/2010
user5, 9/9/2010, 9/20/2010

users taking leaving on 9th would be user开发者_Python百科2, user5
users taking leaving on 12th would be user5
users taking leaving on 15th would be user4, user5

The query should not contain database specific constructs, it needs to run on h2 / mysql / postgres using hibernate as the ORM layer


SELECT  userId
FROM    mytable
WHERE   '2010-09-09' BETWEEN startDate AND COALESCE(endDate, startDate)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜