的特定的增量項目計數考慮一個圖表,顯示各種水果的數量,它們在存在:MySQL的:獲取的是滿足條件
x---------x-----x
| FRUIT | QTY |
x---------x-----x
| Apple | 4 |
| Orange | 5 |
| Mango | 4 |
| Grape | 1 |
| Plum | 2 |
| Peach | 2 |
x---------x-----x
從這個表我要查詢水果的數量(即算一算具有特定數量從0開始,並在MAX(數量)結束的記錄數),所以我的結果集是:
x-----x-------x
| QTY | COUNT |
x-----x-------x
| 0 | 0 | //0 fruits have 0 quantity
| 1 | 1 | //1 fruit (Grape) has 1 quantity
| 2 | 2 | //2 fruits (Plum, Peach) have 2 quantity
| 3 | 0 | //0 fruits have 3 quantity
| 4 | 2 | //2 fruits (Apple, Mango) have 4 quantity
| 5 | 1 | //1 fruit (Orange) has 5 quantity
x-----x-------x
如何才能實現這一目標?