Использование SQL функции EXTRACT для возвращения одной части даты / времени

29.12.2011

Синтаксис:
EXTRACT(unit FROM date)

Значения unit:

Unit Value
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH

Пример:
1
2
3
4
5
6
SELECT *, EXTRACT(MONTH FROM date1) AS m
FROM items
WHERE publish = 1 
GROUP BY m 
HAVING EXTRACT(DAY FROM date1) = "03" OR EXTRACT(MONTH FROM date1) = "09"
ORDER BY date1

Категории: SQL
Яндекс.Метрика