Returns the minimum value within the requested window.
For more information on usage, please refer to Window Functions.
Syntax
MIN( <expression> ) OVER ( [ PARTITION BY <partition_by> ] )
Parameters
| Parameter | Description | Supported input types |
|---|
<expression> | A value used for the MIN function | Any |
<partition_by> | An expression used for the PARTITION BY clause. | Any |
Example
The example below shows each player’s score alongside the lowest score in their level. Unlike a regular MIN() aggregation, the window function keeps one row per player while also showing the partition minimum.
SELECT
nickname,
level,
current_score,
MIN(current_score) OVER (PARTITION BY level) AS lowest_score
FROM
(VALUES
('kennethpark', 9, 76),
('sabrina21', 9, 90),
('burchdenise', 10, 79),
('ymatthews', 10, 85),
('rileyjon', 10, 80)
) AS t(nickname, level, current_score)
ORDER BY level, nickname;
| nickname text | level int | current_score int | lowest_score int null |
|---|
| kennethpark | 9 | 76 | 76 |
| sabrina21 | 9 | 90 | 76 |
| burchdenise | 10 | 79 | 79 |
| rileyjon | 10 | 80 | 79 |
| ymatthews | 10 | 85 | 79 |
Rows: 5Execution time: 1.81ms