Answer the question
In order to leave comments, you need to log in
How to group overlapping values in SQL?
There is a table:
table
xy
500 1.0
400 2.3
101 4.1
select
case when x in (500,400,101) then 'three'
case when x in (500,400) then 'one'
else '' end as "group",
sum (y) as "sum",
from table
group by
"group"
Answer the question
In order to leave comments, you need to log in
group by case when x in (500,400,101) then 'three' case when x in (500,400) then 'one' else '' end
It would be possible to add another table of groups with x and group fields. Join your table with a new table by the x field and group by the group field. In your version, at some point, the case can become very complex and unreadable, and to add a new group, you always need to add a request, and this is not buzzing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question