LoginSignup
5
2

More than 5 years have passed since last update.

MariaDB10.2 でサポートされる「window関数」について

Posted at

MariaDB10.2で実装予定の「window関数」について、現時点でサポートされている関数をまとめました。

【現時点でサポートされている関数】

ROW_NUMBER, RANK, DENSE_RANK, PERCENT_RANK, CUME_DIST, NTILE
FIRST_VALUE, LAST_VALUE, NTH_VALUE, LEAD, LAG
および、全ての主要な集計関数(SUM とか MIN とか)

MariaDB 10.2の環境で以下のクエリを実行すれば、各関数が使用できることを確認できます。

========================

create table t1 (i int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);

select i, min(i) OVER ( partition by null order by i ) from t1;

select i, first_value(i) OVER ( partition by null order by i rows between current row and current row ) from t1;

select i, lag(i) OVER ( partition by null order by i ) from t1;

========================

※ なお、first_value()関数にはバグがあることが報告されています。
  こちらは、10.2.4で修正されます。
  https://jira.mariadb.org/browse/MDEV-11746

MariaDB 10.2 のwindow関数に関しては、以下のマニュアルおよび記事に記載があります。

https://mariadb.com/kb/en/mariadb/window-functions/
https://www.fromdual.com/mariadb-10-2-window-function-examples

なお、window関数および関連マニュアルについては、現在「開発中」のステータスのため、
今後内容が変更される可能性があります。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2