clickhouse学习笔记-5-函数整理
日期类
- 时间或日期截取函数(to)—— 返回非日期
| 函数 | 用途 | 举例 | 结果 |
|---|---|---|---|
| toYear() | 取日期或时间日期的年份 | toYear(toDateTime(‘2018-12-11 11:12:13’)) toYear(toDate(‘2018-12-11’)) | 2018 |
| toMonth() | 取日期或时间日期的月份 | toMonth(toDateTime(‘2018-12-11 11:12:13’)) toMonth(toDate(‘2018-12-11’)) | 12 |
| toDayOfMonth() | 取日期或时间日期的天(1-31) | toMonth(toDayOfMonth(‘2018-12-11 11:12:13’)) toMonth(toDayOfMonth(‘2018-12-11’)) | 11 |
| toDayOfWeek() | 取日期或时间日期的星期(星期一为1,星期日为7)。 | toDayOfWeek(toDateTime(‘2018-12-11 11:12:13’)) toDayOfWeek(toDate(‘2018-12-11’)) | 2 |
| toHour() | 取时间日期的小时 | toHour(toDateTime(‘2018-12-11 11:12:13’)) | 11 |
| toMinute() | 取时间日期的分钟 | toMinute(toDateTime(‘2018-12-11 11:12:13’)) | 12 |
| toSecond() | 取时间日期的秒 | toSecond(toDateTime(‘2018-12-11 11:12:13’)) | 13 |
| toMonday() | 取时间日期最近的周一(返回日期) | toMonday(toDate(‘2018-12-11’)) toMonday(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-10 |
| toTime() | 将时间日期的日期固定到某一天,保留原始时间 | toTime(toDateTime(‘2018-12-11 11:12:13’)) |
- 时间或日期截取函数(toStartOf)—— 返回日期
| 函数 | 用途 | 举例 | 结果 |
|---|---|---|---|
| toStartOfMonth() | 取日期或时间日期的月份的第一天,返回日期 | toStartOfMonth(toDateTime(‘2018-12-11 11:12:13’)) toStartOfMonth(toDate(‘2018-12-11’)) | 2018-12-01 |
| toStartOfQuarter() | 取日期或时间日期的季度的第一天,返回日期 | toStartOfQuarter(toDateTime(‘2018-12-11 11:12:13’)) toStartOfQuarter(toDate(‘2018-12-11’)) | 2018-10-01 |
| toStartOfYear() | 取日期或时间日期的年份的第一天,返回日期 | toStartOfYear(toDateTime(‘2018-12-11 11:12:13’)) toStartOfYear(toDate(‘2018-12-11’)) | 2018-01-01 |
| toStartOfMinute() | 截取时间日期到分钟(之后归零),返回日期 | toStartOfMinute(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-11 11:12:00 |
| toStartOfFiveMinute() | 截取时间日期到最近的5的倍数分钟(之后归零),返回日期 | toStartOfFiveMinute(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-11 11:10:00 |
| toStartOfFifteenMinutes() | 截取时间日期到最近的15的倍数分钟(之后归零),返回日期 | toStartOfFifteenMinutes(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-11 11:00:00 |
| toStartOfHour() | 截取时间日期到小时(之后归零),返回日期 | toStartOfHour(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-11 11:00:00 |
| toStartOfDay() | 截取时间日期到天(之后归零),返回日期 | toStartOfDay(toDateTime(‘2018-12-11 11:12:13’)) | 2018-12-11 00:00:00 |
| timeSlot() | 将时间日期中,分钟大于等于30的归于30,分钟数小于30的归为00 | timeSlot(toDateTime(‘2018-12-11 11:33:13’)) | 2018-12-11 11:30:00 |
- 日期或时间日期生成函数
| 函数 | 用途 | 举例 | 结果 |
|---|---|---|---|
| now() | 生成当前时间日期 | now() | 2018-12-13 10:10:12 |
| today() | 生成今天的日期 | today() | 2018-12-13 |
| yesterday() | 生成昨天的日期 | yesterday() | 2018-12-12 |
类型转化类函数
| 函数 | 用途 | 举例 | 结果 |
|---|---|---|---|
| toDecimal32() | 将数值型或者含有非数字的字符串进行精度保留 | toDecimal32(23.12291, 3) | 23.122 |
| toDecimal64() | 将数值型或者含有非数字的字符串进行精度保留 | ||
| toDecimal128() | 将数值型或者含有非数字的字符串进行精度保留 |