the query result
select ( LENGTH(testid) - LENGTH(replace(testid, '/', '')) ) as num_slashes, count(*) from test.1 where isdeleted = false group by ( LENGTH(testid) - LENGTH(replace(testid, '/', '')) ) ORDER BY COUNT(*)
from database returned :
i would like to replaced the 0, 1, 2 to master1, master2, master3.
what query should I used so the query result will be
Advertisement
Answer
You can use:
select (case ( LENGTH(testid) - LENGTH(replace(testid, '/', '')) ) when 1 then 'master1' when 2 then 'master2' when 3 then 'master3' end) as num_slashes, count(*) from test.1 where isdeleted = false group by ( LENGTH(testid) - LENGTH(replace(testid, '/', '')) ) order by COUNT(*)