共用方式為


bitmap_count 函式

適用於:檢查標示為是 Databricks SQL 檢查標示為是 Databricks Runtime 13.3 LTS 和更新版本

傳回代表位圖之字串中 BINARY 設定的位數。 此函式通常用來計算相異值與 bitmap_bucket_number()bitmap_construct_agg() 函式。

若要計算表示式中的 BIGINT 位,請使用 bit_count 函式

語法

bitmap_count(expr)

引數

傳回

BIGINT,即 >=0

範例

> SELECT bitmap_count(X'00');
 0

> SELECT bitmap_count(X'');
 0

> SELECT bitmap_count(X'7700CC');
 10

-- Count the number of distinct values
> SELECT sum(num_distinct) AS num_distinct
    FROM (SELECT bitmap_bucket_number(val),
                 bitmap_count(bitmap_construct_agg(bitmap_bit_position(val)))
            FROM VALUES(1), (2), (1), (-1), (5), (0), (5) AS t(val)
            GROUP BY ALL) AS distinct_vals_by_bucket(bucket, num_distinct)
  5