MySQL Version: since 8.0
Window Functions
A window function is an SQL function where the input values are taken from a “window” of one or more rows in the results set of a SELECT statement.
一个window function 是一个SQL函数,它的input是从一个“SELECT语句结果集中一行或多行的 window”中获取。与普通聚合函数的区别在于它使用关键字 OVER
。
window functions 不能使用DISTINCT
关键字,同时,window functions 只能出现在结果集(result set) 和 SELECT 语句的 ORDER BY 中。
TOP 5 each group
1 | SELECT t1.project_id, t1.user_id FROM project_user t1 WHERE 5 > ( |