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

ANY_VALUE seems to ignore HAVING clause when used in conjunction with GROUP BY #327

Open
anonimitoraf opened this issue Jun 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@anonimitoraf
Copy link

anonimitoraf commented Jun 28, 2024

What happened?

As per title (see below for more info)

What did you expect to happen?

I expected the query below to return:

+---------------------------------+---------------------------------+
|           least_sales           |           most_sales            |
+---------------------------------+---------------------------------+
|  {"sold":"10","fruit":"apples"} |  {"sold":"20","fruit":"apples"} |
| {"sold":"10","fruit":"bananas"} | {"sold":"30","fruit":"bananas"} |
| {"sold":"10","fruit":"oranges"} | {"sold":"10","fruit":"oranges"} |
|   {"sold":"40","fruit":"pears"} |   {"sold":"40","fruit":"pears"} |
+---------------------------------+---------------------------------+

Instead, it incorrectly returns (note apples and bananas:

+---------------------------------+---------------------------------+
|           least_sales           |           most_sales            |
+---------------------------------+---------------------------------+
|  {"sold":"10","fruit":"apples"} |  {"sold":"10","fruit":"apples"} |
| {"sold":"30","fruit":"bananas"} | {"sold":"30","fruit":"bananas"} |
| {"sold":"10","fruit":"oranges"} | {"sold":"10","fruit":"oranges"} |
|   {"sold":"40","fruit":"pears"} |   {"sold":"40","fruit":"pears"} |
+---------------------------------+---------------------------------+

How can we reproduce it (as minimally and precisely as possible)?

WITH
  Store AS (
    SELECT 20 AS sold, "apples" AS fruit
    UNION ALL
    SELECT 10 AS sold, "apples" AS fruit
    UNION ALL
    SELECT 40 AS sold, "pears" AS fruit
    UNION ALL
    SELECT 10 AS sold, "oranges" AS fruit
    UNION ALL
    SELECT 30 AS sold, "bananas" AS fruit
    UNION ALL
    SELECT 10 AS sold, "bananas" AS fruit
  )
SELECT
  ANY_VALUE(x HAVING MIN sold) AS least_sales,
  ANY_VALUE(x HAVING MAX sold) AS most_sales
FROM Store x
GROUP BY fruit

Anything else we need to know?

At face value, it looks like it just takes the first row.

@anonimitoraf anonimitoraf added the bug Something isn't working label Jun 28, 2024
@anonimitoraf anonimitoraf changed the title ANY_VALUE seems to ignore HAVING clause ANY_VALUE seems to ignore HAVING clause when used in conjunction with GROUP BY Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant