If you want a company to count for only one regular expression, you can do:
select (case when REGEXP_LIKE(company_name, '(*)A. en P.$') then '(*)A. en P.$'
when REGEXP_LIKE(company_name, '(*)A.C.$') then '(*)A.C.$'
when REGEXP_LIKE(company_name, '(*)GmbH$') then '(*)GmbH$'
when REGEXP_LIKE(company_name, '(*)A/S$') then '(*)A/S$'
end), count(*)
from company
group by (case when REGEXP_LIKE(company_name, '(*)A. en P.$') then '(*)A. en P.$'
when REGEXP_LIKE(company_name, '(*)A.C.$') then '(*)A.C.$'
when REGEXP_LIKE(company_name, '(*)GmbH$') then '(*)GmbH$'
when REGEXP_LIKE(company_name, '(*)A/S$') then '(*)A/S$'
end);
If you want to count a company for each match, then this is one way:
with patterns(pattern) as (
select '(*)A. en P.$' from dual union all
select '(*)A.C.$' from dual union all
select '(*)GmbH$' from dual union all
select '(*)A/S$' from dual
)
select p.pattern, count(*)
from company c join
patterns p
on regexp_like(c.company_name, p.pattern)
group by p.pattern;
Some notes about your patterns:
- I am not sure what
(*)
is. You don't need anything at the beginning because regular expressions find the pattern in the string; they don't start at the beginning of the string.
.
is a special character in regular expressions that is basically any single character.