Mit bedingter Aggregation:
SELECT
SUM(price < 15) `Less than 15`,
SUM(price >= 15 AND price <= 30) `Between 15 and 30`,
SUM(price > 30) `More than 30`
FROM `table`
WHERE is_active=1
In MySql ein boolescher Ausdruck wie price < 15 wird als 0 ausgewertet für false oder 1 für true .
Sehen Sie sich die Demo
an .
Ergebnisse:
| Less than 15 | Between 15 and 30 | More than 30 |
| ------------ | ----------------- | ------------ |
| 1 | 1 | 1 |