我正在使用oracle dbms,并且在Employe
表中有一列Birthdate
。我想编写一个查询,以显示下周生日的员工。这个对吗 ?
select name
from employe
where to_char(birthdate,'DD-MM')=to_char(next_day(sysdate,1)+7,'DD-MM');
正确的解决方案是
SELECT name
FROM employe
WHERE to_char(birthdate
/* "move" the birthdate to the current year
to get a reliable week number */
+ CAST((EXTRACT(year FROM current_date)
- EXTRACT(year FROM birthdate)) || '-0'
AS INTERVAL YEAR TO MONTH),
'IW')
= to_char(current_date + 7, 'IW');
该IW
格式返回包含日期的ISO周,这可能是您要查找的日期。如果您在星期天开始一周,则在两个日期中添加一个。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句