I am using Oracle SQL and I want to group some different rows that \'like\' function results. To elaborate with an example:
Let\'s assume I have a table MESA w
I would do it this way -- only requires a single change to add additional types of fruit.
WITH fruits AS (
SELECT 'APPLE' fruit FROM DUAL
UNION ALL
SELECT 'ORANGE' fruit FROM DUAL
)
SELECT fruit, count(*)
FROM MESA m, fruits
WHERE m.str LIKE '%FRUIT%'
AND m.str LIKE '%' || fruits.fruit || '%'
GROUP BY fruit
If your strings are reliably in the format you showed in your sample data, I would consider changing the predicate to one condition, WHERE m.str LIKE 'FRUIT%' || fruits.fruit ||'%'
.