Reputation: 1115
Is it possible to "merge" 2 groups obtained after a SQL statement that use group by. For example if I have a field size ENUM('extra-small, 'small', 'medium', 'large', extra-large') and then I run this query SELECT * from clothes GROUP BY size;
, but for in one case I would like to get in result "extra-small" and "small" in the same group. Is this possible with SQL?
Upvotes: 3
Views: 2352
Reputation: 1027
yes, you can:
select count(*)
, case size
when 'extra-large'
then 'large'
else size end as grouped_size
from sizes
group by grouped_size
demo: http://sqlfiddle.com/#!2/ae3fa/2
Upvotes: 6
Reputation: 166396
How about using MySQL GROUP_CONCAT(expr)
This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.
Also have a look at MySQL – The GROUP_CONCAT() function
Upvotes: 0