Posts

Showing posts with the label join

SQL merge minimum time difference

Image
Clash Royale CLAN TAG #URR8PPP SQL merge minimum time difference I'm having trouble with a SQL statement that is a bit over my skill level. Running this in a DB2 datawarehouse. I need to join two columns (CODE1 and CODE2) from TABLE2 into TABLE1 based on some IDs and the minimum time difference between a date in TABLE1 (STARTDATE) and a date in TABLE2 (TIME_SENT). The statement below shows what I'm trying to do, but having issues with ordering of group by and having clause. group by having SELECT * FROM TABLE1 LEFT JOIN (SELECT B.ID1, B.ID2, D.CODE1, D.CODE2 FROM TABLE1 B, TABLE2 D WHERE D.STATUS = '7' GROUP BY B.ID1, B.ID2 HAVING ABS(B.STARTDATE - D.TIME_SENT) = MIN(ABS(B.STARTDATE - D.TIME_SENT)) TABLE2 ON TABLE1.ID1 = TABLE2.ID1 AND TABLE1.ID2 = TABLE2.ID2; Appreciate any help with this. STRUCTURE TABLE1: --------------------------------------------------------- | ID1 (VARCHAR) | ID2 (VARCHAR) | STARTDATE (TIMESTAMP) | --...

Ansible - joining two nested lists without the same key

Image
Clash Royale CLAN TAG #URR8PPP Ansible - joining two nested lists without the same key I am currently trying to combine two different dictionaries together. The thing that ties them together is the login field, but this is not the "key" in both dicts. --- - hosts: localhost gather_facts: no vars: userlist: tom123: guid: "tom" sally: guid: "sally" userteamlist: tom: teams: "group4, group6, group5" sally: teams: "group1, group2, group3" How do I get these two lists to merge based on the "guid"? The "guid" is the key in one list (userteamlist) and a "value" (guid) in the other list (userlist). I have used this Stackoverflow link for joining two dicts with the same key, but have not figured out to do this with key+subelement. Thoughts? Apologies all, I am looking strictly for an Ansible solution to this problem. ...

Subtle issue with joining/merging dataframes with the same column names

Image
Clash Royale CLAN TAG #URR8PPP Subtle issue with joining/merging dataframes with the same column names So I have a main set of data that looks like this: value_num code value_letter 1 CDX A 2 DEF B 3 RPQ C 4 EEE D 5 FFX E 6 TRE F And two other tables which we'll call map1 and map2 song album_code song_code Song1 CDX GIB Song2 DEF FRE Song3 RPQ SSS song album_code song_code Song4 REA EEE Song5 VEY FFX Song6 LFM TRE I want to join the main table with map1 where album_code is joined on code. Then I want to join map2 on this new table where song_code is joined on code. Ideally the final result looks like this: value_num code value_letter song album_code song_code 1 CDX A Song1 CDX GIB 2 DEF B Song2 DEF FRE 3 RPQ C Son...