我正在尝试使用以下查询获取过去 30 天的计数 -
SELECT date_occured, COUNT(*) FROM problem
WHERE date_occured >= (CURRENT_DATE - 30)
GROUP BY date_occured;
//date_occured field is of type DATE.
基本上,在我的查询中,我试图只比较条件中的日期部分date_occured >= (CURRENT_DATE - 30)
,但它似乎也比较了时间。
我按如下方式尝试了 TRUNC -
TRUNC(date_occured) >= TRUNC(CURRENT_DATE - 30)
但是当运行查询时它永远不会返回。
我也试过——
SELECT date_occured, COUNT(*) FROM problem
GROUP BY date_occured
HAVING TRUNC(date_occured) >= TRUNC(CURRENT_DATE - 30);
再一次,它永远不会回来。
如何仅比较 Oracle 中两个 DATE 值的日期部分?