Table a custnum acctnum opendate 123abcd789 546787123 1/5/2023 785bdef234 578541216…
- User
Table a cust_num acct_num open_date 123abcd789 546787123 1/5/2023 785bdef234 578541216 2/20/2023 546weyt548 213054623 3/21/2023 987wyte412 702598124 3/21/2023 762wwer880 675478953 3/27/2023
Table b cust_num status snapshot_date 123abcd789 student 1/3/2023 123abcd789 PR 1/4/2023 123abcd789 student 1/5/2023 123abcd789 worker 1/6/2023 785bdef234 student 2/18/2023 785bdef234 student 2/19/2023 785bdef234 worker 2/20/2023 785bdef234 worker 2/21/2023 785bdef234 PR 2/22/2023 546weyt548 student 3/17/2023 546weyt548 student 3/18/2023 546weyt548 student 3/19/2023 546weyt548 student 3/20/2023 546weyt548 worker 3/21/2023 546weyt548 worker 3/22/2023 546weyt548 PR 3/23/2023 546weyt548 PR 3/24/2023 546weyt548 PR 3/25/2023 762wwer880 student 3/21/2023 762wwer880 student 3/22/2023 762wwer880 student 3/23/2023 762wwer880 student 3/24/2023 762wwer880 student 3/25/2023 762wwer880 PR 3/26/2023 762wwer880 PR 3/27/2023 762wwer880 worker 3/28/2023 762wwer880 worker 3/29/2023 762wwer880 worker 3/30/2023
WITH Sales_Performance AS ( SELECT DISTINCT CAST(a.acct_num AS BIGINT) AS acct_num, CAST(a.prim_own_cif_id AS BIGINT) AS cust_cid, SUBSTR(TRIM(a.opn_dt), 1, 7) AS year_month, a.opn_dt AS open_date, a.type AS products, CASE WHEN d.immigration_cat_cd IN ('000','999','C1','FC1','FC2','FC3','EN2','PV1','PV2','SW1','SW2','SW3','SE2','STP','C2','NV5') THEN 'PR' WHEN d.immigration_cat_cd IN ('FW','FW0') THEN 'FW' WHEN d.immigration_cat_cd IN ('S','S00') THEN 'IS' ELSE 'Regular_Customers' END AS MCB_Category FROM table_a a LEFT JOIN ( SELECT DISTINCT CAST(party_id AS BIGINT) AS party_id, immigration_cat_cd, start_date, date_sub(coalesce(LEAD(start_date) OVER (PARTITION BY party_id ORDER BY start_date ), current_date),1) AS end_date FROM (SELECT party_id, immigration_cat_cd, businesseffectivedate AS start_date, RANK() OVER (PARTITION BY party_id, immigration_cat_cd ORDER BY businesseffectivedate) AS rank FROM table_b ) d WHERE rank = 1 ) d ON lpad(a.prim_own_cif_id,15,'0') = lpad(d.party_id,15,'0') WHERE trim(a.channel) NOT IN ('Branch','CCC') AND trim(a.type) NOT IN ('US$','GTSP') AND a.opn_dt > '2022-12-31' AND a.opn_dt < '2023-04-01' AND (d.party_id IS NULL OR (a.opn_dt BETWEEN d.start_date AND d.end_date) OR d.start_date IS NULL) ) SELECT * FROM Sales_Performance;
Now use my above query and above tables and get me the output
- Assistant
- User
Provide the output of the info i provided
- Assistant
Given the limitations and inconsistencies in the SQL query and the corresponding descriptions of Table A and Table B, we'll instead focus on a simpler, direct analysis of the provided data. We'll determine the customer status at the point of their account opening by examining the dates in the tables.
Let's manually review the customer status at or just before their account opening dates based on the provided data:
-
Customer 123abcd789
- Account Open Date: 1/5/2023
- Status just before or on opening: (last status on 1/5/2023)
-
- User
Now can you share the code that gives this output in hive sql
- Assistant
- User
What was the problem of the code i shared above
- Assistant