NumberBin (NoSQL クエリ)

適用対象: NoSQL

数値式の値を、指定されたビン サイズの倍数に丸めます。

構文

NumberBin(<numeric_expr> [, <bin_size>])

引数

説明
numeric_expr 数値式。評価されて、結果の値は指定されたビン サイズの倍数に丸められます。
bin_size"(省略可能)" 値を丸めるときに使用するビン サイズを指定する数値。 この数値は、指定されない場合は既定値の 1 です。

戻り値の型

数値を返します。

この最初の例では、さまざまなビン サイズを持つ 1 つの静的な数値をビンにします。

SELECT VALUE {
    roundToNegativeHundreds: NumberBin(37.752, -100),
    roundToTens: NumberBin(37.752, 10),
    roundToOnes: NumberBin(37.752, 1),
    roundToZeroes: NumberBin(37.752, 0),
    roundToOneTenths: NumberBin(37.752, 0.1),
    roundToOneHundreds: NumberBin(37.752, 0.01)
}
[
  {
    "roundToNegativeHundreds": 100,
    "roundToTens": 30,
    "roundToOnes": 37,
    "roundToOneTenths": 37.7,
    "roundToOneHundreds": 37.75
  }
]

次の例では、既存の項目のフィールドを使用します。

[
  {
    "name": "Ignis Cooking System",
    "price": 155.23478,
    "category": "portable-cooking"
  }
]

このクエリでは、関数を使用して前のフィールドを丸めます。

SELECT
    p.name,
    NumberBin(p.price, 0.01) AS price
FROM
    products p
WHERE
    p.category = "portable-cooking"
[
  {
    "name": "Ignis Cooking System",
    "price": 155.23
  }
]

解説

  • 指定したビン サイズが 0 の場合、この関数は undefined を返します。
  • 既定のビン サイズは 1 です。 このビン サイズが実質的に返す数値は、次の整数に丸められます。

関連項目