Seat Type Quantity left
Business 23
Economy 27
First 15
Total quantity left : ?
DBMS = MySQL
我已经尝试了以下SQL来打印以上信息
$sql = "SELECT SeatType, COUNT(SeatType)AS quantity
FROM seat
WHERE SeatAvailable = 'Yes'
GROUP BY SeatType
";
我如何总结剩余的总量(例如:23 + 27 + 25)?
谢谢高级的帮助...
最佳答案
SELECT COALESCE(SeatType, 'Total quantity left') `Seat Type`,
COUNT(SeatType)AS quantity
FROM seat
WHERE SeatAvailable = 'Yes'
GROUP BY SeatType WITH ROLLUP
SQLFiddle Demo
GROUP BY Modifier