Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Join two tables having time period data

$
0
0

You might just ask: how must an SQL statement look like for that?

 

From what I understand, you want to find the matching "cc" value for every record in the first table.

Matching means that the time frame specified by "Datefrom" and "Dateto" lies within the time frame in the second table (also limited by "Datefrom" and "Dateto").

 

I will leave aside any possible problem where "Datefrom" might not be smaller or equal "Dateto" and that any range of validity might overlap.

This is up to your modeling and design to care about.

 

Given that requirement you could write the query like this:

 

SELECT ...

FROM

<first_table> T1 outer join <second_table> T2

on  T1."Datefrom" >= T2."Datefrom"

and T1."Dateto" <= T2."Dateto"

 

If that doesn't do it for you, please do as Dubravko wrote and provide the SQL commands to create the tables so that we can work with that easily.

 

- Lars


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>