我试图复制这一问题在monetdb,我不相信支持TOP命令,只能在最外层的结果使用极限。
如果我可以使用TOP
的话,我相信这个命令会给我我想要的东西。 在那里,这不是大量低效率的一个合理的选择? 我需要在表上,很快就会最大程度的发挥我的服务器的RAM运行此。 谢谢!
CREATE TABLE nearest_matches AS
( SELECT a.* ,
(
SELECT TOP 1 svcmon
FROM person_table AS z
WHERE a.yr = z.yr AND a.person_id = z.person_id
ORDER BY abs( z.svcmon - a.svcmon )
) AS nearest_month
FROM event_table AS a ) WITH DATA
从斯特凡Manegold在CWI
嗨,
弥补我的建议给我所需的语义的理解:
对于一部开拓创新的问题:
create table a (id int, sales int, date timestamp);
create table b (id int, goal int, date timestamp);
select a.*, b.* from a,b, (select a.date as a_date, max(b.date) as b_date from a,b where b.date < a.date group by a.date) as ab where a.date = ab.a_date and b.date = ab.b_date;
下面的问题:
create table event_table (yr int, person_id int, svcmon int, payload string);
create table person_table (yr int, person_id int, svcmon int, payload string);
select * from (select e.yr, e.person_id, e.svcmon as e_svcmon, e.payload as e_payload, p.svcmon as p_svcmon, p.payload as p_payload, row_number() over (partition by e.yr,e.person_id order by abs(e.svcmon - p.svcmon) asc) as pos from event_table e , person_table p where e.yr = p.yr and e.person_id = p.person_id) as ep where pos = 1;
知道实际的模式,将有助于理解“每个事件”是否被确定年,PERSON_ID(正如我上面假设),或者,比方说,(年,为person_id,svcmon)(在这种情况下e.svcmon应加隔断BY子句)。
知道实际的模式也可能有助于拉动投影出来的内部查询,因为这样缩小了中间结果的大小(S)...
最佳斯特凡
文章来源: monetdb sql method to locate or match by the nearest value, without a TOP or LIMIT