0
id timestamp status
167 6/28/2016 8:05:58 PM 0
167 6/28/2016 8:06:02 PM 0
167 6/28/2016 8:06:05 PM 0
167 6/28/2016 8:08:06 PM 0
167 6/28/2016 8:08:10 PM 0
167 6/28/2016 8:08:13 PM 3
167 6/28/2016 8:08:17 PM 3
167 6/28/2016 8:10:41 PM 3
167 6/28/2016 8:10:45 PM 3
167 6/28/2016 8:10:48 PM 3
167 6/28/2016 8:10:51 PM 0
167 6/28/2016 8:10:55 PM 0
167 6/28/2016 8:26:40 PM 0
167 6/28/2016 8:26:44 PM 0
167 6/28/2016 8:26:47 PM 3
167 6/28/2016 8:26:50 PM 3
167 6/28/2016 8:29:19 PM 3
167 6/28/2016 8:29:23 PM 3
167 6/28/2016 8:29:26 PM 0
167 6/28/2016 8:29:29 PM 0
167 6/28/2016 8:30:33 PM 0
167 6/28/2016 8:30:37 PM 0
167 6/28/2016 8:30:40 PM 3
167 6/28/2016 8:30:44 PM 3
167 6/28/2016 8:33:11 PM 3
167 6/28/2016 8:33:15 PM 3
167 6/28/2016 8:33:18 PM 0
167 6/28/2016 8:33:21 PM 0
167 6/28/2016 8:33:45 PM 0
167 6/28/2016 8:33:48 PM 0
167 6/28/2016 8:33:52 PM 0
167 6/28/2016 8:33:55 PM 3
167 6/28/2016 8:33:58 PM 3
167 6/28/2016 8:34:59 PM 3
167 6/28/2016 8:35:03 PM 3
以上數據是從我們IoT
系統之一,它主要講述在一臺機器是在WRT什麼狀態timestamp
與0 being Stop and 3 being running.
查詢優化在Dashdb
我要計算在每小時生產的零件一小時,爲此邏輯是檢查機器狀態是否從3變爲0,然後產生一個aprt。
我寫了下面的查詢,然後給出預期的結果。查詢工作正常,如果我們爲3-5機器執行它,如果在24小時內對100臺機器執行相同的操作,則需要很長時間。目前,查詢每個設備需要14分鐘1小時的數據。
紅外線使用 - DashDB in bluemix
,數據,這個數據庫是從cloudant
再次bluemix
服務推動。
====
select a.runstatus,a.runcount ,b.runstatus,b.runcount from (SELECT a.run_status runstatus, count(a.run_status) runcount
FROM machinedata a where a.run_status <> (SELECT b.run_status
FROM machinedata b
WHERE a.machine_id = b.machine_id
AND a.timestamp > b.timestamp
ORDER BY b.timestamp DESC
LIMIT 1
) and a.machine_id = 167 and a.run_status=0 AND a.`timestamp` BETWEEN '2016-06-28 20:00:01'
AND '2016-06-28 20:59:59' group by a.run_status) as a,
(SELECT a.run_status runstatus, count(a.run_status) runcount
FROM machinedata a where a.run_status <> (SELECT b.run_status
FROM machinedata b
WHERE a.machine_id = b.machine_id
AND a.timestamp > b.timestamp
ORDER BY b.timestamp DESC
LIMIT 1
) and a.machine_id = 167 and a.run_status=3 AND a.`timestamp` BETWEEN '2016-06-28 20:00:01'
AND '2016-06-28 20:59:59' group by a.run_status) as b
HI託斯滕,語法「按訂單」 –
@LohithKumar給錯誤我附近再次驗證它和它的作品,因爲我粘貼它的罰款。 –
這裏是我爲我的測試創建的表'''CREATE TABLE MACHINEDATA(ID INT,TIMESTAMP TIMESTAMP,STATUS INT)'' –