You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The NTILE window function is returning incorrect results in some cases. In the example below, the function divides the result set in more buckets than specified in the function argument.
2 - Execute this query, which gives incorrect results
SELECT dep, name, salary, NTILE(4) OVER (ORDER BY hire_date) FROM employees;
It should divide the 10 rows into 4 buckets, but it returns a 5 for the last row, which is incorrect.
The function returns correct results in the case of 2 buckets, for example.
Date: 2020-02-21 10:25:12 +0100
From: @bernardom29
To: SQL devs <>
Version: -- development
CC: @PedroTadim
Last updated: 2020-02-24 09:32:58 +0100
Comment 27576
Date: 2020-02-21 10:25:12 +0100
From: @bernardom29
The NTILE window function is returning incorrect results in some cases. In the example below, the function divides the result set in more buckets than specified in the function argument.
How to reproduce:
1 - Create table and add values
create table employees (dep varchar(10), name varchar(20), salary double, hire_date date);
insert into employees values
('mgmt', 'Smith',81,str_to_date('10-08-2019', '%d-%m-%Y')),
('dev', 'Jones',55,str_to_date('9-08-2019', '%d-%m-%Y')),
('sls', 'Williams',55,str_to_date('14-07-2019', '%d-%m-%Y')),
('sls', 'Taylor',62,str_to_date('13-08-2019', '%d-%m-%Y')),
('dev', 'Brown',62,str_to_date('6-06-2019', '%d-%m-%Y')),
('mgmt', 'Davies',84,str_to_date('4-06-2019', '%d-%m-%Y')),
('sls', 'Evans',87,str_to_date('1-09-2019', '%d-%m-%Y')),
('sls', 'Wilson',72,str_to_date('21-09-2019', '%d-%m-%Y')),
('sls', 'Thomas',72,str_to_date('12-06-2019', '%d-%m-%Y')),
('mgmt', 'Johnson',100,str_to_date('12-07-2019', '%d-%m-%Y'));
2 - Execute this query, which gives incorrect results
SELECT dep, name, salary, NTILE(4) OVER (ORDER BY hire_date) FROM employees;
It should divide the 10 rows into 4 buckets, but it returns a 5 for the last row, which is incorrect.
The function returns correct results in the case of 2 buckets, for example.
Comment 27577
Date: 2020-02-21 11:19:22 +0100
From: MonetDB Mercurial Repository <>
Changeset 670675a1ce57 made by Pedro Ferreira pedro.ferreira@monetdbsolutions.com in the MonetDB repo, refers to this bug.
For complete details, see https//devmonetdborg/hg/MonetDB?cmd=changeset;node=670675a1ce57
Changeset description:
The text was updated successfully, but these errors were encountered: