选择查询帮助更新

时间:2019-01-07 21:35:23

标签: sql oracle

我在下面选择了每日数据查询,如何修改以获取整月的数据

select *
from BAU_SDT_INV_USER
where trunc(CHECKED_DATE) = to_date('2018/12/18', 'YYYY/MM/DD')

4 个答案:

答案 0 :(得分:1)

如果要使用Oracle的整个月:

where checked_date >= date '2018-12-01' and
      checked_date < date '2019-01-01'

答案 1 :(得分:0)

也许是这样吗?

select * from BAU_SDT_INV_USER 
where CHECKED_DATE >= to_date('2018/12/01', 'YYYY/MM/DD')
  and CHECKED_DATE < to_date('2019/01/01', 'YYYY/MM/DD')

答案 2 :(得分:0)

select *
from BAU_SDT_INV_USER
where trunc(CHECKED_DATE) BETWEEN to_date('2018/12/01', 'YYYY/MM/DD')  
  AND to_date('2018/12/31', 'YYYY/MM/DD')

采用更加索引友好的方法

select *
from BAU_SDT_INV_USER
where CHECKED_DATE between ADD_MONTHS(sysdate, -1) and sysdate

编辑,请注意,between子句包含在内。您也可以使用

select *
from BAU_SDT_INV_USER
where CHECKED_DATE >= ADD_MONTHS(to_date(:inputDate, 'YYYY/MM/DD'), -1)  
  and CHECKED_DATE < TO_DATE(:input_Date,'YYYY/MM/DD'); 

答案 3 :(得分:0)

如果性能不是查询的重点,则在比较的两端按月trunc

select *
from BAU_SDT_INV_USER
where trunc(CHECKED_DATE, 'mm') = trunc( to_date('2018/12/18', 'YYYY/MM/DD'), 'mm')