0

When I run the query, I get this:

enter image description here

Whereas I need it to be grouped according to the CASE statement below:

select business_name, 
case 
when business_name like '%school%' then 'School'
when business_name like '%restaurant%' then 'Restaurant'
when business_name like '%caf%' then 'Cafe'
else 'other'
end
as business_classification
from sf_restaurant_health_violations;
Thedh
  • 3
  • 1
  • Strings are case sensitive. Change to `ilike` which ignores case. – Isolated Oct 12 '22 at 18:27
  • `like` is case-sensitive. You may either use the case-insensitive `ilike` or [regular expression](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) match, i.e. `when business_name ~* 'school' then 'School'`. I prefer the second option. – Stefanov.sm Oct 12 '22 at 18:29
  • or read [How to make my postgresql database use a case insensitive collation?](https://stackoverflow.com/questions/18807276/how-to-make-my-postgresql-database-use-a-case-insensitive-collation) – Luuk Oct 12 '22 at 18:31
  • when using postgresql, this seems to be true: [Note that as of PostgreSQL v12, non deterministic collations DO NOT support LIKE and LIKE](https://stackoverflow.com/questions/18807276/how-to-make-my-postgresql-database-use-a-case-insensitive-collation#comment109473983_59101567) – Luuk Oct 12 '22 at 19:06

0 Answers0