I have a field named “ColorCode” in a MySQL table that has values such as these:
28373 GYY green
23423 HH red
23423 HH green
2343 QWE red
SKDJF blue
green
What would be the SQL statement to show how many occurances of each color, something like this PHP-influenced pseudo code:
SELECT COUNT(*) FROM products GROUP BY END(EXPLODE(ColorCode));
fugly, but something like this
If you’re running this query frequently, definitely consider splitting that ‘last’ value into its own field so you can at least index it. performance is going to be abysmal on large tables.