开发者

how to join two tables from separate db's with timestamps that differ slightly with sql

开发者 https://www.devze.com 2023-01-16 01:49 出处:网络
I need to know how to join two tables together with t开发者_如何学编程heir timestamps. The timestamps differ consistently by 1.8 seconds every time and there is a data entry every half hour. any ideas

I need to know how to join two tables together with t开发者_如何学编程heir timestamps. The timestamps differ consistently by 1.8 seconds every time and there is a data entry every half hour. any ideas?


This is a very weak link. They are consistently 1.8 seconds apart on that environment, but when you change anything, that can change.

If you must join by time stamp, generate the time stamp in code at the start of the commit, and set the timestamps to that value, so at the very least they are the same.

A better solution is to create a key to keep the data points together. Maybe a batchID if you are trying to tie together entries in the same half hour set.


This did the job:

SELECT * FROM db1.dataset, db2.dataset where extract(year from db1.dataset.timestamp) = extract(year from db2.dataset.timestamp)
and
extract(day from db1.dataset.timestamp) = extract(day from db2.dataset.timestamp)
and
extract(month from db1.dataset.timestamp) = extract(month from db2.dataset.timestamp)
and
extract(hour from db1.dataset.timestamp) = extract(hour from db2.dataset.timestamp)
and
extract(minute from db1.dataset.timestamp) <= extract(minute from db2.dataset.timestamp)+5
and
extract(minute from db1.dataset.timestamp) >= extract(minute from db2.dataset.timestamp)- 5
0

精彩评论

暂无评论...
验证码 换一张
取 消