2023-10-17 23:36:14 +08:00
|
|
|
[discrete]
|
2023-05-11 23:02:27 +08:00
|
|
|
[[esql-date_trunc]]
|
|
|
|
=== `DATE_TRUNC`
|
|
|
|
Rounds down a date to the closest interval. Intervals can be expressed using the
|
|
|
|
<<esql-timespan-literals,timespan literal syntax>>.
|
|
|
|
|
|
|
|
[source,esql]
|
|
|
|
----
|
|
|
|
FROM employees
|
2023-08-23 00:20:05 +08:00
|
|
|
| EVAL year_hired = DATE_TRUNC(1 year, hire_date)
|
2023-05-11 23:02:27 +08:00
|
|
|
| STATS count(emp_no) BY year_hired
|
|
|
|
| SORT year_hired
|
|
|
|
----
|