U kunt voorwaardelijke aggregatie gebruiken:
SELECT fruit, SUM(CASE `a-b-c`
WHEN 'a' THEN 1
WHEN 'b' THEN 2
WHEN 'c' THEN 3
END) AS total
FROM tbl_fruits
GROUP BY fruit;
Uitgang:
╔═════════╦═══════╗
║ fruit ║ total ║
╠═════════╬═══════╣
║ banana ║ 3 ║
║ orange ║ 7 ║
╚═════════╩═══════╝
Of gebruik ELT/FIELD
:
SELECT fruit, SUM(ELT(FIELD(`a-b-c`,'a','b','c'),1,2,3)) AS total
FROM tbl_fruits
GROUP BY fruit;