Oracle SQL NOT BETWEEN不返回正确的数据

时间:2015-11-09 20:56:34

标签: sql oracle between

我希望退回所有当前未雇用的商品,这是由每件商品的开始和结束日期定义的。

我创建了以下代码,但这不会返回正确的结果。

public class RequestFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return inflater.inflate(R.layout.req_list_fragment, container, false);
}

public void setText(String text) {
    TextView t = (TextView) getView().findViewById(R.id.title);
    t.setText(text);
}

public TextView getText(){
    TextView t = (TextView) getView().findViewById(R.id.title);
    return t;
}

我已经在我的表格中加入了一小部分内容来解释我的需求:

SELECT DISTINCT item.ITEM_ID, details.barcode
  FROM item
  JOIN details ON item.ITEM_ID = details.ITEM_ID
 WHERE (item.HIRE_DATE NOT BETWEEN TO_DATE('01/05/2015','dd/mm/yyyy')
                               AND TO_DATE('11/05/2015','dd/mm/yyyy'))
   AND item.END_DATE NOT BETWEEN TO_DATE('01/05/2015','dd/mm/yyyy')
                             AND TO_DATE('11/05/2015','dd/mm/yyyy');

在上表中,如果我将开始日期设置为 Hire_Date | End_Date | Item_ID ------------------------------------- 01/01/2015 | 03/01/2015 | ItemID_12 06/01/2015 | 07/01/2015 | ItemID_12 03/01/2015 | 10/01/2015 | ItemID_5 02/01/2015 | 04/01/2015 | ItemID_8 12/01/2015 | 15/01/2015 | ItemID_10 11/01/2015 | 20/01/2015 | ItemID_4 15/01/2015 | 16/01/2015 | ItemID_5 01/01/2015 | 03/01/2015 | ItemID_3 07/01/2015 | 10/01/2015 | ItemID_3 01/01/2015 | 07/01/2015 | ItemID_2 10/01/2015 | 15/01/2015 | ItemID_12 16/01/2015 | 20/01/2015 | ItemID_3 05/01/2015 | 15/01/2015 | ItemID_8 16/01/2015 | 20/01/2015 | ItemID_10 10/01/2015 | 15/01/2015 | ItemID_2 ,将结束日期设置为06/01/2015,则只会返回10/01/2015& ItemID_4因为在该日期范围内根本不使用这些内容。

1 个答案:

答案 0 :(得分:0)

也许你只是在寻找另一种表达方式:

HIRE_DATE > TO_DATE('11/05/2015','dd/mm/yyyy') OR END_DATE < TO_DATE('01/05/2015','dd/mm/yyyy')