Skip to content
Advertisement

How to combine some similar pattern data in one column of mysql, to get the count?

I have a table like below

enter image description here

From this table, I want to get the counts of SearchParams, which I tried like this:

enter image description here

But I want all the data which is matching the pattern “TVE-xxxx” should be combined as “TVE” and the count.

Please help.

Advertisement

Answer

Use a CASE statement to determine the value on which you group by:

select 
  case when searchParam like 'TVE-%' then 'TVE' else searchParam end groupParam,
  count(*) counter
from careinsight.testtable
group by groupParam
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement