PL / SQL添加7天到datetime并在该日期之间获得一些东西

时间:2012-12-06 22:16:42

标签: oracle datetime plsql

好的,所以我在PL / SQL上有数据库。

这是我的SQL问题:

SELECT t.AC_NUMBER, t.DATE, a.comment_1, a.comment_2, a.comment_3, a.comment_4
  FROM proddba.cust_info t
       left join proddba.cust_descr a on a.ac_number=t.ac_number
 where a.open_date=(select min(b.open_date) 
                      from proddba.cust_descr b 
                     where b.ac_number=t.ac_number 
                       and b.open_date>=t.date 
                       and b.open_dane<=t.date+7days)

如何动态添加+7天到目前为止?

第二,如果有两个相同的数据,如何只获得一个日期min(b.open_date)?我应该使用不同吗?

(select distinct min(b.open_date) 
   from proddba.cust_descr b 
  where b.ac_number=t.ac_number 
    and b.open_date>=t.date 
    and b.open_dane<=t.date+7days)

如果必须从数据库中获取大约15000条记录,这应该有用吗?

最好的问候

1 个答案:

答案 0 :(得分:1)

您只需向DATE

添加一些天数即可
t.date + 7

将在DATE中的t.date添加7天(因此时间组件将被保留)。

MIN已经使子查询返回单个数据值 - 不需要添加DISTINCT,因为它不会更改输出。我不确定你试图描述的问题是由于获得多行而产生的 - 你可能担心外部查询会返回两行具有相同a.open_date值的行,并且你试图确保得到只有一排?