Middle
Kuidas töötasid analüütilised funktsioonid (akenfunktsioonid)?
sobes.tech AI
Vastus AI-lt
Analytical functions (window functions) allow performing calculations over sets of rows related to the current row, without grouping data. For example, you can calculate a moving sum, ranking, or average within data sections.
Example of usage in SQL:
SELECT
employee_id,
department_id,
salary,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees;
Here, for each employee, the salary rank within their department is calculated. I used window functions for data analysis, simplifying complex queries and improving performance by avoiding subqueries and additional joins.