I am looking for a solution for the following problem:
SELECT CASE WHEN p.value LIKE '%foo%' THEN 'foos' WHEN p.value LIKE '%bar%' THEN 'bars' WHEN p.value LIKE '%bakar%' THEN 'bakars' ELSE p.value END as value, COUNT(*) as count FROM table_a p GROUP BY value
Values:
foo, bar, foo and bar, bakar, bakarbar, foobar
The result of this query:
value count foos 3 bars 2 bakars 1
This code successfully considers occurrences, but CASE stops at the first match. Is there any way to do this?
value count foos 3 bars 4 bakars 2
sql mysql
Kadel
source share