0

假设我们有桌子error_log,很容易像:

+-------------+---------------+
| error_token | date_recorded |
+-------------+---------------+
| error_1     | 05.03.2017    |
+-------------+---------------+
| error_2     | 05.03.2017    |
+-------------+---------------+
| error_3     | 10.03.2017    |
+-------------+---------------+
| error_4     | 30.03.2017    |
+-------------+---------------+

获取从本周开始今天发生的所有错误的最佳方法是什么。

如果我们想得到从本月初到今天之间的所有错误,也是一样的。

4

1 回答 1

1

当您说“直到今天”时,我假设这意味着最多但不包括今天小于 trunc(sysdate)的任何部分

select *
from error_log
where date_recorded >= trunc(sysdate,'W') -- beginning of week
and date_recorder < trunc(sysdate) -- optional

select *
from error_log
where date_recorded >= trunc(sysdate,'MONTH') -- beginning of month
and date_recorder < trunc(sysdate) -- optional

TRUNC

于 2017-11-03T10:27:06.817 回答