看板 Database 關於我們 聯絡資訊
資料庫名稱:SQLite 資料庫版本:3.9.2 內容/問題描述: 各位前輩好 ._. 目前想要把一個小時內的值, 以 15mins 做分割,取出 4 個各落點裡面最高的值。 以及一個 24hrs 的平均值。 當然分開寫是沒有什麼難度, 不過會想試試看有沒有比較聰明的寫法可以一次處理。 不過想不到什麼好的解法,所以就上來問問看了~ 還煩請前輩們賜教 <(_ _)> 謝謝。 -- //now to 15mins select max(status), time from records where time < 1449142204 AND time >= 1449141304; //15mins to 30mins select max(status), time from records where time < 1449141304 AND time >= 1449140404; //30mins to 45mins select max(status), time from records where time < 1449140404 AND time >= 1449139504; //45mins to 60mins select max(status), time from records where time < 1449139504 AND time >= 1449138604; //24hrs avg select round(avg(status), 1) from records where time < 1449142204 AND time >= 1449055804; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.43.200 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1449143263.A.187.html
konkonchou: 查詢條件放另一資料表再 left join 回原資料表 12/03 21:16
swallowcc: <(_ _)> 我試試看, 感謝~ 12/03 22:51
chippclass: http://i.imgur.com/StVj8Rn.png 不確定是否是好方法 12/03 23:28
swallowcc: 感謝你,有方法都可以試試看XD 12/03 23:39