[SQL ] 一次查詢多組max value值

看板Database作者 (罹患重度能年病的燕叔)時間10年前 (2015/12/03 19:47), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
資料庫名稱: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

12/03 21:16, , 1F
查詢條件放另一資料表再 left join 回原資料表
12/03 21:16, 1F

12/03 22:51, , 2F
<(_ _)> 我試試看, 感謝~
12/03 22:51, 2F

12/03 23:28, , 3F
不確定是否是好方法
12/03 23:28, 3F

12/03 23:39, , 4F
感謝你,有方法都可以試試看XD
12/03 23:39, 4F
文章代碼(AID): #1MO2lV67 (Database)