Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Ori
Contributor III

left join on conditions

hi guys,

I got a sql query that I wish to transfer to Qlik syntax.

basically the sql query creates an outer join between a date range and a cluster_id list so that each cluster has all the date range and then another join adds another field ("event_id") based on a combined on condition.

now up to the outer join no problems, handled that quite easily.

the addition of the event id is the tricky part, each event id has a begin date and an end date.

in sql we simply use an on condition where the timestamp is greater than the beginning date and lower than the end date.

it was hinted that the solution might be related to the interval match function but I can seem to get the syntax right.

example of table one (timestamp and cluster_id) 

Ori_0-1671519599542.png

example of table 2 - out of which i want to return the event id based on the timestamp and the cluster id (each event id exists under a specific cluster)

Ori_1-1671519841771.png

end result :

Ori_2-1671520063921.png

emphasis, the existence on blank timestamps  in which there are no event id's are important, we want to maintain the full timestamp range even if there are no event ids for the entire range.

thanks!

ori.

 

 

Labels (3)
1 Solution

Accepted Solutions
Ori
Contributor III
Author

Rubber duck debugging and a bit of online search did the trick.

Left Join (table a)

IntervalMatch(timestamp1, cluster_id)
LOAD created_at,
end_date,
cluster_id
Resident table_b;

and then another left join to get the event id

left join (table a)

load
created_at,
end_date,
cluster_id,
event_id

resident table_b;

 

perhaps it could have been done more efficiently, if anyone knows of a way i'd love to hear it.

View solution in original post

1 Reply
Ori
Contributor III
Author

Rubber duck debugging and a bit of online search did the trick.

Left Join (table a)

IntervalMatch(timestamp1, cluster_id)
LOAD created_at,
end_date,
cluster_id
Resident table_b;

and then another left join to get the event id

left join (table a)

load
created_at,
end_date,
cluster_id,
event_id

resident table_b;

 

perhaps it could have been done more efficiently, if anyone knows of a way i'd love to hear it.