[英]Use data from mysql db to present the number of active concurrent processes at a given time in a html table
我的數據庫中有一個數據集,如下所示,它顯示了進程的開始時間和持續時間(以秒為單位):
+---------------------+----------+
| start_time | duration |
+---------------------+----------+
| 2013-10-01 10:00:00 | 15.6 |
| 2013-10-01 10:00:03 | 0.8 |
| 2013-10-01 10:00:03 | 4.5 |
| 2013-10-01 10:00:14 | 22.8 |
| 2013-10-01 10:00:28 | 30.9 |
+---------------------+----------+
有了這些數據,我希望能夠每隔15秒在瀏覽器中顯示一個表,以查看在指定間隔內有多少個活動的進程。 用戶將能夠指定日期和時間范圍,以便可以像這樣使用查詢:
SELECT start_time, duration FROM process_period
WHERE start_time >= "2013-10-01 10:00:00" AND start_time < "2013-10-24 11:00:00"
最好的方法是什么? 所需的輸出應為:
Interval time: Number of active processes:
2013-10-01 10:00:00 1
2013-10-01 10:00:15 2
2013-10-01 10:00:30 2
2013-10-01 10:00:45 1
您必須在查詢中使用兩件事。 要計算在特定時間內啟動的進程數量,請使用“ GROUPBY”,並設置間隔使用“ HAVING”。 由於您正在使用“ GROUPBY”,因此無法在查詢中使用“ WHERE”子句。 檢查followinf小提琴http://sqlfiddle.com/#!2/a82fa/4/0
編輯:或如果您想要進程計數在特定的時間間隔,則請執行以下操作
select count(*) as process_count from processdata where start_time between '2013-10-01 10:15:00' and '2013-10-01 10:23:00'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.