βΉοΈ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 7.7 months ago (distributed domain, exempt) |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://github.com/ClickHouse/ClickHouse/issues/61313 |
| Last Crawled | 2025-08-20 10:51:00 (7 months ago) |
| First Indexed | not set |
| HTTP Status Code | 200 |
| Meta Title | group by count with null values in the grouping key returns hard to understand result Β· Issue #61313 Β· ClickHouse/ClickHouse Β· GitHub |
| Meta Description | Describe the unexpected behaviour I'm having trouble understanding how nulls are handled when used as grouping keys. I can't tell if there's something I'm missing here, or if this is a bug in ClickHouse. How to reproduce ClickHouse serve... |
| Meta Canonical | null |
| Boilerpipe Text | Describe the unexpected behaviour I'm having trouble understanding how nulls are handled when used as grouping keys. I can't tell if there's something I'm missing here, or if this is a bug in ClickHouse. How to reproduce ClickHouse server version: bce519d15486 :) select version();
SELECT version()
Query id: ef482266-bbdb-4b62-ad14-3838c14c66cb
ββversion()βββ
β 23.12.4.15 β
ββββββββββββββ
1 row in set. Elapsed: 0.001 sec.
Example: bce519d15486 :) CREATE OR REPLACE TABLE ibis_testing.topk (x Nullable(Int64)) ENGINE = Memory;
CREATE OR REPLACE TABLE ibis_testing.topk
(
`x` Nullable(Int64)
)
ENGINE = Memory
Query id: 76f08dbb-380e-4336-b156-f71b992ca09e
Ok.
0 rows in set. Elapsed: 0.006 sec.
bce519d15486 :) INSERT INTO ibis_testing.topk VALUES (1), (1), (NULL);
INSERT INTO ibis_testing.topk FORMAT Values
Query id: fec175db-566c-4019-8752-b36dcfc95f2c
Ok.
3 rows in set. Elapsed: 0.002 sec.
bce519d15486 :) select x, count(*), count(1), count(), countIf(x is null) from topk group by x;
SELECT
x,
count(*),
count(1),
count(),
countIf(x IS NULL)
FROM topk
GROUP BY x
Query id: df3b4079-c6df-455f-ad2b-259612b42df6
βββββxββ¬βcount()ββ¬βcount()ββ¬βcount()ββ¬βcountIf(isNull(x))ββ
β α΄Ία΅α΄Έα΄Έ β 0 β 0 β 0 β 0 β
β 1 β 3 β 3 β 3 β 1 β
ββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄βββββββββββββββββββββ
2 rows in set. Elapsed: 0.002 sec.
Expected behavior I would expect the count() aggregations to return 1 for NULL and 2 for 1 , and the countIf aggregation to return 1 for NULL and 0 for 1 . |
| Markdown | [Skip to content](https://github.com/ClickHouse/ClickHouse/issues/61313#start-of-content)
## Navigation Menu
Toggle navigation
[Sign in](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FClickHouse%2FClickHouse%2Fissues%2F61313)
Appearance settings
- Product
- [GitHub Copilot Write better code with AI](https://github.com/features/copilot)
- [GitHub Spark New Build and deploy intelligent apps](https://github.com/features/spark)
- [GitHub Models New Manage and compare prompts](https://github.com/features/models)
- [GitHub Advanced Security Find and fix vulnerabilities](https://github.com/security/advanced-security)
- [Actions Automate any workflow](https://github.com/features/actions)
- [Codespaces Instant dev environments](https://github.com/features/codespaces)
- [Issues Plan and track work](https://github.com/features/issues)
- [Code Review Manage code changes](https://github.com/features/code-review)
- [Discussions Collaborate outside of code](https://github.com/features/discussions)
- [Code Search Find more, search less](https://github.com/features/code-search)
Explore
- [Why GitHub](https://github.com/why-github)
- [All features](https://github.com/features)
- [Documentation](https://docs.github.com/)
- [GitHub Skills](https://skills.github.com/)
- [Blog](https://github.blog/)
- Solutions
By company size
- [Enterprises](https://github.com/enterprise)
- [Small and medium teams](https://github.com/team)
- [Startups](https://github.com/enterprise/startups)
- [Nonprofits](https://github.com/solutions/industry/nonprofits)
By use case
- [DevSecOps](https://github.com/solutions/use-case/devsecops)
- [DevOps](https://github.com/solutions/use-case/devops)
- [CI/CD](https://github.com/solutions/use-case/ci-cd)
- [View all use cases](https://github.com/solutions/use-case)
By industry
- [Healthcare](https://github.com/solutions/industry/healthcare)
- [Financial services](https://github.com/solutions/industry/financial-services)
- [Manufacturing](https://github.com/solutions/industry/manufacturing)
- [Government](https://github.com/solutions/industry/government)
- [View all industries](https://github.com/solutions/industry)
[View all solutions](https://github.com/solutions)
- Resources
Topics
- [AI](https://github.com/resources/articles/ai)
- [DevOps](https://github.com/resources/articles/devops)
- [Security](https://github.com/resources/articles/security)
- [Software Development](https://github.com/resources/articles/software-development)
- [View all](https://github.com/resources/articles)
Explore
- [Learning Pathways](https://resources.github.com/learn/pathways)
- [Events & Webinars](https://resources.github.com/)
- [Ebooks & Whitepapers](https://github.com/resources/whitepapers)
- [Customer Stories](https://github.com/customer-stories)
- [Partners](https://partner.github.com/)
- [Executive Insights](https://github.com/solutions/executive-insights)
- Open Source
- [GitHub Sponsors Fund open source developers](https://github.com/sponsors)
- [The ReadME Project GitHub community articles](https://github.com/readme)
Repositories
- [Topics](https://github.com/topics)
- [Trending](https://github.com/trending)
- [Collections](https://github.com/collections)
- Enterprise
- [Enterprise platform AI-powered developer platform](https://github.com/enterprise)
Available add-ons
- [GitHub Advanced Security Enterprise-grade security features](https://github.com/security/advanced-security)
- [Copilot for business Enterprise-grade AI features](https://github.com/features/copilot/copilot-business)
- [Premium Support Enterprise-grade 24/7 support](https://github.com/premium-support)
- [Pricing](https://github.com/pricing)
Search or jump to...
# Search code, repositories, users, issues, pull requests...
[Search syntax tips](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax)
# Provide feedback
Cancel
Submit feedback
# Saved searches
## Use saved searches to filter your results more quickly
Cancel
Create saved search
[Sign in](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FClickHouse%2FClickHouse%2Fissues%2F61313)
[Sign up](https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=ClickHouse%2FClickHouse)
Appearance settings
Resetting focus
You signed in with another tab or window. [Reload](https://github.com/ClickHouse/ClickHouse/issues/61313) to refresh your session. You signed out in another tab or window. [Reload](https://github.com/ClickHouse/ClickHouse/issues/61313) to refresh your session. You switched accounts on another tab or window. [Reload](https://github.com/ClickHouse/ClickHouse/issues/61313) to refresh your session.
Dismiss alert
{{ message }}
[ClickHouse](https://github.com/ClickHouse) / **[ClickHouse](https://github.com/ClickHouse/ClickHouse)** Public
- [Notifications](https://github.com/login?return_to=%2FClickHouse%2FClickHouse)
You must be signed in to change notification settings
- [Fork 7.6k](https://github.com/login?return_to=%2FClickHouse%2FClickHouse)
- [Star 42.4k](https://github.com/login?return_to=%2FClickHouse%2FClickHouse)
- [Code](https://github.com/ClickHouse/ClickHouse)
- [Issues 4.4k](https://github.com/ClickHouse/ClickHouse/issues)
- [Pull requests 669](https://github.com/ClickHouse/ClickHouse/pulls)
- [Discussions](https://github.com/ClickHouse/ClickHouse/discussions)
- [Actions](https://github.com/ClickHouse/ClickHouse/actions)
- [Projects 0](https://github.com/ClickHouse/ClickHouse/projects)
- [Wiki](https://github.com/ClickHouse/ClickHouse/wiki)
- [Security](https://github.com/ClickHouse/ClickHouse/security)
[Uh oh\!](https://github.com/ClickHouse/ClickHouse/security)
[There was an error while loading.](https://github.com/ClickHouse/ClickHouse/security) [Please reload this page](https://github.com/ClickHouse/ClickHouse/issues/61313).
- [Insights](https://github.com/ClickHouse/ClickHouse/pulse)
Additional navigation options
- [Code](https://github.com/ClickHouse/ClickHouse)
- [Issues](https://github.com/ClickHouse/ClickHouse/issues)
- [Pull requests](https://github.com/ClickHouse/ClickHouse/pulls)
- [Discussions](https://github.com/ClickHouse/ClickHouse/discussions)
- [Actions](https://github.com/ClickHouse/ClickHouse/actions)
- [Projects](https://github.com/ClickHouse/ClickHouse/projects)
- [Wiki](https://github.com/ClickHouse/ClickHouse/wiki)
- [Security](https://github.com/ClickHouse/ClickHouse/security)
- [Insights](https://github.com/ClickHouse/ClickHouse/pulse)
# group by count with null values in the grouping key returns hard to understand result \#61313
[New issue](https://github.com/login?return_to=)
Copy link
[New issue](https://github.com/login?return_to=)
Copy link
Closed
[\#61393](https://github.com/ClickHouse/ClickHouse/pull/61393)
Closed
[group by count with null values in the grouping key returns hard to understand result](https://github.com/ClickHouse/ClickHouse/issues/61313#top)
\#61313
[\#61393](https://github.com/ClickHouse/ClickHouse/pull/61393)
Copy link
Assignees
[](https://github.com/CurtizJ)
Labels
[bugConfirmed user-visible misbehaviour in official release](https://github.com/ClickHouse/ClickHouse/issues?q=state%3Aopen%20label%3A%22bug%22)Confirmed user-visible misbehaviour in official release
[](https://github.com/cpcloud)
## Description
[](https://github.com/cpcloud)
[cpcloud](https://github.com/cpcloud)
opened
[on Mar 13, 2024](https://github.com/ClickHouse/ClickHouse/issues/61313#issue-2184239082)
Issue body actions
**Describe the unexpected behaviour**
I'm having trouble understanding how nulls are handled when used as grouping keys. I can't tell if there's something I'm missing here, or if this is a bug in ClickHouse.
**How to reproduce**
ClickHouse server version:
```
bce519d15486 :) select version();
SELECT version()
Query id: ef482266-bbdb-4b62-ad14-3838c14c66cb
ββversion()βββ
β 23.12.4.15 β
ββββββββββββββ
1 row in set. Elapsed: 0.001 sec.
```
Example:
```
bce519d15486 :) CREATE OR REPLACE TABLE ibis_testing.topk (x Nullable(Int64)) ENGINE = Memory;
CREATE OR REPLACE TABLE ibis_testing.topk
(
`x` Nullable(Int64)
)
ENGINE = Memory
Query id: 76f08dbb-380e-4336-b156-f71b992ca09e
Ok.
0 rows in set. Elapsed: 0.006 sec.
bce519d15486 :) INSERT INTO ibis_testing.topk VALUES (1), (1), (NULL);
INSERT INTO ibis_testing.topk FORMAT Values
Query id: fec175db-566c-4019-8752-b36dcfc95f2c
Ok.
3 rows in set. Elapsed: 0.002 sec.
bce519d15486 :) select x, count(*), count(1), count(), countIf(x is null) from topk group by x;
SELECT
x,
count(*),
count(1),
count(),
countIf(x IS NULL)
FROM topk
GROUP BY x
Query id: df3b4079-c6df-455f-ad2b-259612b42df6
βββββxββ¬βcount()ββ¬βcount()ββ¬βcount()ββ¬βcountIf(isNull(x))ββ
β α΄Ία΅α΄Έα΄Έ β 0 β 0 β 0 β 0 β
β 1 β 3 β 3 β 3 β 1 β
ββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄βββββββββββββββββββββ
2 rows in set. Elapsed: 0.002 sec.
```
**Expected behavior**
I would expect the `count()` aggregations to return 1 for `NULL` and `2` for `1`, and the `countIf` aggregation to return `1` for `NULL` and `0` for `1`.
## Metadata
## Metadata
### Assignees
- [CurtizJ](https://github.com/CurtizJ)
### Labels
[bugConfirmed user-visible misbehaviour in official release](https://github.com/ClickHouse/ClickHouse/issues?q=state%3Aopen%20label%3A%22bug%22)Confirmed user-visible misbehaviour in official release
### Type
No type
### Projects
No projects
### Milestone
No milestone
### Relationships
None yet
### Development
No branches or pull requests
## Issue actions
## Footer
Β© 2025 GitHub, Inc.
### Footer navigation
- [Terms](https://docs.github.com/site-policy/github-terms/github-terms-of-service)
- [Privacy](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement)
- [Security](https://github.com/security)
- [Status](https://www.githubstatus.com/)
- [Docs](https://docs.github.com/)
- [Contact](https://support.github.com/?tags=dotcom-footer)
- Manage cookies
- Do not share my personal information
You canβt perform that action at this time. |
| Readable Markdown | null |
| Shard | 174 (laksa) |
| Root Hash | 6325672905007345774 |
| Unparsed URL | com,github!/ClickHouse/ClickHouse/issues/61313 s443 |