Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: the group function does not return the correct result #16563

Open
1 of 2 tasks
cdmikechen opened this issue Oct 3, 2024 · 1 comment
Open
1 of 2 tasks

bug: the group function does not return the correct result #16563

cdmikechen opened this issue Oct 3, 2024 · 1 comment
Labels
C-bug Category: something isn't working

Comments

@cdmikechen
Copy link

cdmikechen commented Oct 3, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Version

v1.2.615

What's Wrong?

The cumulative (like for annual) sum function does not return the expected value:

databend: wrong result and not sure what to do with the result.
image

postgresql: right result we expected.
image

How to Reproduce?

databend:

drop table test_group;
create table test_group (
  input_date date,
  value decimal(10,2)
);
insert into test_group values ('2024-01-01', 100),('2024-01-01', 200),('2024-01-02', 400),('2024-01-02', 800);

select input_date, sum(value), 
(select sum(value)
	    from test_group b
	    where b.input_date >= DATE_TRUNC(YEAR, input_date)
	      and b.input_date <= a.input_date) as total
from test_group a
group by input_date;

postgresql:

drop table test_group;
create table test_group (
  input_date date,
  value decimal(10,2)
);
insert into test_group values ('2024-01-01', 100),('2024-01-01', 200),('2024-01-02', 400),('2024-01-02', 800);

select input_date, sum(value), 
(select sum(value)
    from test_group b
    where b.input_date >= date_trunc('year', input_date)
      and b.input_date <= a.input_date) as total
from test_group a
group by input_date;

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@cdmikechen cdmikechen added the C-bug Category: something isn't working label Oct 3, 2024
@cdmikechen
Copy link
Author

cdmikechen commented Oct 3, 2024

After validation of more row values, it appears that the result of sum is multiplied by the number of same data rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant