メインコンテンツまでスキップ

bitmap_union_count

bitmap_union_count

概要

ビットマップのセットの合併を返し、合併の要素数を返します。この関数はv2.3からサポートされています。

構文

BIGINT bitmap_union_count(BITMAP value)

パラメータ

value: ビットマップのセットです。サポートされるデータ型はBITMAPです。

戻り値

BIGINT型の値を返します。

ウェブページの固有ビュー(UV)を計算します。user_idがINT型の場合、後の2つのクエリは同等です。

mysql> select * from test
+---------+---------+
| page_id | user_id |
+---------+---------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
+---------+---------+

mysql> select page_id,count(distinct user_id) from test group by page_id;
+---------+-------------------------+
| page_id | count(DISTINCT user_id) |
+---------+-------------------------+
| 1 | 2 |
| 2 | 1 |
+---------+-------------------------+

mysql> select page_id,bitmap_union_count(to_bitmap(user_id)) from test group by page_id;
+---------+----------------------------------------+
| page_id | bitmap_union_count(to_bitmap(user_id)) |
+---------+----------------------------------------+
| 1 | 2 |
| 2 | 1 |
+---------+----------------------------------------+