获取从今天到本周初的日期记录

get date records between today and beginning of the current week

假设我们有 table error_log, sth 很容易像:

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

获取从本周初今天.[=12=发生的所有错误的最佳方法是什么]

如果我们想要获取从 本月初 今天 .[=12 之间的所有错误,也是一样的=]

当你说 "until today" 时,我假设这意味着直到但不包括今天 小于 trunc(sysdate)[=12 的任何部分=]

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