-
Notifications
You must be signed in to change notification settings - Fork 25k
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
SQL: [Docs] Add example for custom bucketing with CASE #41787
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,31 @@ an error message would be returned, mentioning that *'foo'* is of data type *key | |
which does not match the expected data type *integer* (based on result *10*). | ||
=============================== | ||
|
||
[[sql-functions-conditional-case-groupby-custom-buckets]] | ||
[TIP] | ||
=============================== | ||
CASE can be used as a GROUP BY key in a query to facilitate custom bucketing | ||
and assign descriptive names to those buckets. If for example the number of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
values for a key are too many or, simply, ranges of those values are more | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
interesting than every single value, CASE can create custom buckets as in the | ||
following example: | ||
|
||
[source, sql] | ||
SELECT count(*) AS count, | ||
CASE WHEN NVL(languages, 0) = 0 THEN 'zero' | ||
WHEN languages = 1 THEN 'one' | ||
WHEN languages = 2 THEN 'bilingual' | ||
WHEN languages = 3 THEN 'trilingual' | ||
ELSE 'multilingual' | ||
END as lang_skills | ||
FROM employees | ||
GROUP BY lang_skills | ||
ORDER BY lang_skills; | ||
|
||
With this query, we can create normal grouping buckets for values _0, 1, 2, 3_ with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
descriptive names, and every value _>= 4_ falls into the _multilingual_ bucket. | ||
=============================== | ||
|
||
[[sql-functions-conditional-coalesce]] | ||
==== `COALESCE` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the TIP header and promote this to a section (
=====
) - I think it's big enough to warrant a proper entry.