冰雹,堆疊!如何選擇按範圍分組的值的計數
我需要選擇按範圍分組的值的計數。
爲了舉例說明,假設我有一個表columm以下值:1,2,4,5,6,8,9,11,13,16
然後,我想retreave他們的數量在5範圍內,像這樣:
From 0 to 4 there is 3 values (1,2,4)
From 5 to 9 there is 4 values (5,6,8,9)
From 10 to 14 there is 2 values (11,13)
From 15 to 19 there is 1 values (16)
而且等等......
我該如何在查詢中做到這一點?
這基本上是Guffa在8分鐘後發佈的想法。 – Andomar 2011-02-27 22:29:37
@Andomar不,它不是。 MySQL(n/5)返回一個小數,即使n不是小數。需要'div' – RichardTheKiwi 2011-02-27 23:27:11
工作應該如此! – NemoStein 2011-03-01 13:07:33