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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With