我需要在特定範圍內0到10秒,0到20秒等內應答呼叫計數。計數將增加,而增量將是不同的計數當前和下一個之間。該百分比將是當前計數/最終計數總數。計數呼叫在一定範圍內應答0到10秒,按組計數
這裏是你可以用數據用於測試的sqlfiddle:callsdetails的http://sqlfiddle.com/#!9/803d2/2
樣品表:
+-----+----------------+----------+----------+---------------+
| id | callid | callerno | duration | status |
+-----+----------------+----------+----------+---------------+
| 634 | 1479097551.228 | 1000 | 2 | complete |
| 635 | 1479102518.248 | 1000 | 12 | complete |
+-----+----------------+----------+----------+---------------+
預期結果:
+------------------------+----------+----------+----------+
| Ranges | Count | Delta | % |
+------------------------+----------+----------+----------+
| Between 0 to 10 secs | 44 | +44 | 84.62 % |
| Between 0 to 20 secs | 48 | +4 | 92.31 % |
| Between 0 to 30 secs | 50 | +2 | 96.15 % |
| Between 0 to 40 secs | 51 | +1 | 98.08 % |
| Between 0 to 50 secs | 51 | +0 | 98.08 % |
| Between 0 to 60 secs | 51 | +0 | 98.08 % |
| Between 0 to 70 secs | 51 | +0 | 98.08 % |
| Between 0 to 80 secs | 52 | +1 | 100.00 % |
| Between 0 to 90 secs | 52 | +0 | 100.00 % |
| Between 0 to 100+ secs | 52 | +0 | 100.00 % |
+------------------------+----------+----------+----------+
Total 52
我能創造什麼現在正在下面查詢,如果你能幫助提供更好的解決方案,請指教。我現在面臨的問題是(優先級)我無法獲得計數和(次要)最終計數總數(52),現在我手動輸入最終計數總數(52)。請幫忙。
SELECT Ranges,Delta,ROUND(Delta/52*100,2) AS '%'
FROM
(
SELECT
(
IF(duration<=10,'10',IF(duration<=20,'20',IF(duration<=30,'30',
IF(duration<=40,'40',IF(duration<=50,'50',
IF(duration<=60,'60',IF(duration<=70,'70',IF(duration<=80,
'80',IF(duration<=90,'90','100+'))))))))))
AS Ranges,COUNT(duration) AS Delta
FROM callsdetails
GROUP BY Ranges
) a
GROUP BY Ranges;
當前結果:
+--------+-------+-------+
| Ranges | Delta | % |
+--------+-------+-------+
| 10 | 44 | 84.62 |
| 20 | 4 | 7.69 |
| 30 | 2 | 3.85 |
| 40 | 1 | 1.92 |
| 80 | 1 | 1.92 |
+--------+-------+-------+
你可以將'UNION'總數計算到最低。原來的桌子怎麼樣? – RealCheeseLord
我在上面的示例表中添加了對原始表格的引用。請指教。 – DarkSilver