作者swallowcc (罹患重度能年病的燕叔)
看板Database
标题[SQL ] max value
时间Thu Dec 3 19:47:40 2015
资料库名称: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://webptt.com/cn.aspx?n=bbs/Database/M.1449143263.A.187.html
1F:→ konkonchou: 查询条件放另一资料表再 left join 回原资料表 12/03 21:16
2F:→ swallowcc: <(_ _)> 我试试看, 感谢~ 12/03 22:51
4F:→ swallowcc: 感谢你,有方法都可以试试看XD 12/03 23:39