mariadbHow to use window functions in Mariadb?
Window functions in MariaDB are used to perform calculations over a set of rows that are related to the current row. They are similar to aggregate functions, but allow for the calculation to be done over a subset of the rows in the table.
Example
SELECT id, name,
AVG(salary) OVER (PARTITION BY dept_id) AS avg_salary
FROM employees
This example will calculate the average salary for each department. The PARTITION BY
clause defines the subset of rows to be used for the calculation.
Code explanation
SELECT
: specifies the columns to be returned in the result setAVG()
: the window function used to calculate the average salaryOVER
: specifies the window for the calculationPARTITION BY
: defines the subset of rows to be used for the calculation
Helpful links
More of Mariadb
- What type to use for a year in Mariadb?
- How to check version of Mariadb?
- How to list users in Mariadb?
- How to use UUID in Mariadb?
- Mariadb partitioning example
- How to work with XML in Mariadb?
- How to use variables in Mariadb?
- Mariadb procedure example
- How to get current year in Mariadb?
- How to change wait_timeout in Mariadb?
See more codes...