如何选择12个月以上的数据?

编程入门 行业动态 更新时间:2024-10-28 18:28:16
本文介绍了如何选择12个月以上的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一张桌子,如下:

caravan_id, description, date_purchased, special_instructions, health&safety_check, notes

health&safety_check是日期字段.

如何对该表中的数据执行SQL查询,以返回health&safety_check早于12个月的所有行.但是,如果可能的话,则以12个月为基础,而不是以今天的日期为基础,例如< 2011年10月12日

How can I perform an SQL query for data in this table that returns all rows which have a health&safety_check older than 12 months. But if possible one that is based on 12 months, not on today's date such as < 10/12/2011

推荐答案

类似的东西

select * from t where add_months("health&safety_check", 12) < sysdate

我假设您不想硬编码当前日期,但很乐意为它使用变量.

I assume you don't want to hardcode the current date but are happy with using a variable for it.

Jeff在评论中提出了一个很好的观点(尽管在Oracle中,您可以在函数上创建索引,以便解决问题).这很容易解决:

Jeff, in the comments, makes a good point (although, in Oracle, you can create an index on a function so you can get around the problem). This is easily fixed:

where "health&safety_check" <add_months(sysdate, -12)

更多推荐

如何选择12个月以上的数据?

本文发布于:2023-10-21 17:00:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:个月   如何选择   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!