bin_at()bin_at()
将值向下舍入为固定大小的“bin”,并控制 bin 的起点。Rounds values down to a fixed-size "bin", with control over the bin's starting point.
(另请参阅 bin function
。)(See also bin function
.)
语法Syntax
bin_at
(
Expression,
BinSize,
FixedPoint)
bin_at
(
Expression,
BinSize,
FixedPoint)
参数Arguments
- 表达式 :数值类型(包括
datetime
和timespan
)的标量表达式,指示要舍入的值。Expression : A scalar expression of a numeric type (includingdatetime
andtimespan
) indicating the value to round. - BinSize:数值类型或
timespan
的标量常量(适用于datetime
或timespan
表达式),指示每个箱的大小。BinSize : A scalar constant of a numeric type ortimespan
(for adatetime
ortimespan
Expression ) indicating the size of each bin. - FixedPoint:与 Expression 类型相同的标量常数,指示 Expression 的一个值,该值是一个“固定点”(即
bin_at(fixed_point, bin_size, fixed_point) == fixed_point
的一个值fixed_point
) 。FixedPoint : A scalar constant of the same type as Expression indicating one value of Expression which is a "fixed point" (that is, a valuefixed_point
for whichbin_at(fixed_point, bin_size, fixed_point) == fixed_point
.)
返回Returns
Expression 下方最接近的 BinSize 倍数,移动后 FixedPoint 将被转换为自身 。The nearest multiple of BinSize below Expression , shifted so that FixedPoint will be translated into itself.
示例Examples
表达式Expression | 结果Result | 注释Comments |
---|---|---|
bin_at(6.5, 2.5, 7) |
4.5 |
|
bin_at(time(1h), 1d, 12h) |
-12h |
|
bin_at(datetime(2017-05-15 10:20:00.0), 1d, datetime(1970-01-01 12:00:00.0)) |
datetime(2017-05-14 12:00:00.0) |
所有 bin 都将处于中午All bins will be at noon |
bin_at(datetime(2017-05-17 10:20:00.0), 7d, datetime(2017-06-04 00:00:00.0)) |
datetime(2017-05-14 00:00:00.0) |
所有 bin 都将在星期日All bins will be on Sundays |
在下面的示例中,注意 "fixed point"
参数将作为一个 bin 返回,其他 bin 根据 bin_size
与其对齐。In the following example, notice that the "fixed point"
arg is returned as one of the bins and the other bins are aligned to it based on the bin_size
. 另请注意,每个日期/时间 bin 表示该 bin 的开始时间:Also note that each datetime bin represents the starting time of that bin:
datatable(Date:datetime, Num:int)[
datetime(2018-02-24T15:14),3,
datetime(2018-02-23T16:14),4,
datetime(2018-02-26T15:14),5]
| summarize sum(Num) by bin_at(Date, 1d, datetime(2018-02-24 15:14:00.0000000))
DateDate | sum_Numsum_Num |
---|---|
2018-02-23 15:14:00.00000002018-02-23 15:14:00.0000000 | 44 |
2018-02-24 15:14:00.00000002018-02-24 15:14:00.0000000 | 33 |
2018-02-26 15:14:00.00000002018-02-26 15:14:00.0000000 | 55 |