我用regularur sql编写了一些查询,但我认为分析函数在第2部分发挥作用
据推测,该数据库每天可获得5000万张飞行汽车记录,每条记录每天记录一辆汽车的位置我需要写一个查询来识别任何超速行驶的超速行驶让我们说每小时超过500英里的超速行驶
然后我需要写另一个查询,确保汽车与任何其他飞行汽车保持50英尺的距离,所以我必须在空中[50英尺高度]等的任何时间识别彼此50英尺内的任何人..
之后我还需要写一个查询给前5%的超速驾驶者,假设城市内的最高速度(包括高速公路)是50英里每小时。 我必须写的查询信息是GPS时间戳,相机的GPS纬度和经度,以及汽车牌照。
这是我到目前为止所拥有的
CREATE OR REPLACE FUNCTION speed(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT, t time) RETURNS FLOAT AS $$
DECLARE
x float = 69.1 * (lat2 - lat1);
y float = 69.1 * (lon2 - lon1) * cos(lat1 / 57.3);
d float = sqrt(x * x + y * y);
tcon float = extract(hour from t);
BEGIN
RETURN d/tcon;
END
$$ LANGUAGE plpgsql;
insert into report
values (1,'04:23:20', 40.23,40.78,1200,1);
insert into report
values(2,'03:21:00', 89.12,-120.56,1300,1);
insert into report
values(3,'18:16:18', 30.12,-4.56,1400,1);
insert into report
values (1,'04:56:00', 75.23,152.78,1200,2);
insert into report
values(2,'06:14:00', 89.12,-12.56,1300,2);
insert into report
values(3,'19:21:10', 60.12, 15.42,1400,2);
select report.carid,speed ((select(report.lat from report where carid = carid and entrynum = entrynum),
select(report.lon from report where carid = carid and entrynum = entrynum),
select(report.lat from report where carid = carid and entrynum = entrynum+1),
select(report.lon from report where carid = carid and entrynum = entrynum+1),
select(report.thours from report where carid = carid and entrynum = entrynum+1)
from report)) as s
我不知道下一步该怎么做