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
- How to get yesterday's date in Mariadb?
- How to get current year in Mariadb?
- What type to use for a year in Mariadb?
- How to work with XML in Mariadb?
- How to use variables in Mariadb?
- How to use the WITH clause in Mariadb?
- How to list available engines in Mariadb?
- How to view Mariadb error log?
- How to use XA transactions in Mariadb?
- How to check version of Mariadb?
See more codes...