条件付き集計を使用できます:
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;
出力:
╔═════════╦═══════╗
║ fruit ║ total ║
╠═════════╬═══════╣
║ banana ║ 3 ║
║ orange ║ 7 ║
╚═════════╩═══════╝
または、ELT/FIELD
を使用します :
SELECT fruit, SUM(ELT(FIELD(`a-b-c`,'a','b','c'),1,2,3)) AS total
FROM tbl_fruits
GROUP BY fruit;