Anda dapat menggunakan agregasi bersyarat:
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;
Keluaran:
╔═════════╦═══════╗
║ fruit ║ total ║
╠═════════╬═══════╣
║ banana ║ 3 ║
║ orange ║ 7 ║
╚═════════╩═══════╝
Atau gunakan ELT/FIELD
:
SELECT fruit, SUM(ELT(FIELD(`a-b-c`,'a','b','c'),1,2,3)) AS total
FROM tbl_fruits
GROUP BY fruit;