Manikandan Arunachalam
Manikandan Arunachalam

Reputation: 1500

group by a column based on a value to a group and all the other as another

I have a table in which a column has values like below.

mango
orange
mango
banana
grape
pineapple

So, I want the result as

mango
other

how can i group this column based on these values.What is the query or is it possible?

Upvotes: 0

Views: 24

Answers (1)

Dan
Dan

Reputation: 11084

Try this:

SELECT IF(`fruit` = 'mango', `fruit`, 'other') AS `someName`, count(*) as `total`
FROM mytable 
GROUP BY `someName`;

Fiddle

Upvotes: 2

Related Questions