Answer the question
In order to leave comments, you need to log in
How to extract dataset from two tables with different time parameters?
Hello.
Prompt or suggest an idea, please, who knows.
Given :
table 1 of the form:
datetime | param1 |
---|---|
2018-08-01 12:10 | red |
2018-08-02 15:20 | green |
2018-08-03 08:30 | blue |
datetime | param2 |
---|---|
2018-08-01 12:15 | 123 |
2018-08-01 13:20 | 234 |
2018-08-01 22:30 | 345 |
2018-08-02 16:10 | 456 |
2018-08-02 21:15 | 567 |
datetime | param2 | param1 |
---|---|---|
2018-08-01 12:15 | 123 | red |
2018-08-01 13:20 | 234 | red |
2018-08-01 22:30 | 345 | red |
2018-08-02 16:10 | 456 | green |
2018-08-02 21:15 | 567 | green |
Answer the question
In order to leave comments, you need to log in
Hmm... For oracle, I would get out like this:
SELECT
t2.datetime
, param2
, (SELECT param1
FROM
(SELECT
t1.param1
, row_number() OVER(ORDER BY t1.datetime DESC) rankparam1
FROM table1 t1
WHERE t2.datetime>=t1.datetime)
WHERE rankparam1 = 1)
as param1
FROM table2 t2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question