Můžete použít case
:
SELECT (CASE WHEN plan_type LIKE 'silver%' THEN 'silver'
WHEN plan_type LIKE 'gold%' THEN 'gold'
WHEN plan_type LIKE 'platinum%' THEN 'platinum'
END) as plan_grp, COUNT(*)
FROM subscriptions
GROUP by (CASE WHEN plan_type LIKE 'silver%' THEN 'silver'
WHEN plan_type LIKE 'gold%' THEN 'gold'
WHEN plan_type LIKE 'platinum%' THEN 'platinum'
END);
Některé databáze umožňují použít alias sloupce v GROUP BY
.