Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Not a Bug
-
10.2.0
-
None
Description
When using an aggregate function as a running function (SUM(...) OVER (...)), identical values are processed together. Which means, if you sum 1 three times, you will get 3 in all records.
MariaDB [test]> CREATE OR REPLACE TABLE employee_salary |
-> (
|
-> name VARCHAR(100) NOT NULL, |
-> salary INT UNSIGNED NOT NULL, |
->
|
-> INDEX idx_salary (salary) |
-> )
|
-> ENGINE InnoDB
|
-> ;
|
Query OK, 0 rows affected (0.56 sec) |
|
|
MariaDB [test]>
|
MariaDB [test]> INSERT INTO employee_salary |
-> (name, salary) |
-> VALUES |
-> ('Fank Zappa', 10000), -- unique values... |
-> ('Jan Anderson', 20000), |
-> ('Ian Gillan', 30000), |
-> ('Ozzy Osbourne', 40000), -- 4000 * 2 |
-> ('Jimmy Page', 40000), |
-> ('Vinnie Colaiuta', 50000), -- 50000 * 3 |
-> ('Frank Zappa', 50000), |
-> ('Joe Satriani', 50000) |
-> ;
|
Query OK, 8 rows affected (0.06 sec) |
Records: 8 Duplicates: 0 Warnings: 0
|
|
|
MariaDB [test]>
|
MariaDB [test]> SELECT |
-> salary, SUM(salary) OVER (ORDER BY salary) AS sum_salary |
-> FROM employee_salary; |
+--------+------------+ |
| salary | sum_salary |
|
+--------+------------+ |
| 10000 | 10000 |
|
| 20000 | 30000 |
|
| 30000 | 60000 |
|
| 40000 | 140000 |
|
| 40000 | 140000 |
|
| 50000 | 290000 |
|
| 50000 | 290000 |
|
| 50000 | 290000 |
|
+--------+------------+ |
8 rows in set (0.00 sec) |