Skip to content

Commit 3f2f5c8

Browse files
authored
Update parking_permit_denormalisation_mc.py (#1957)
add code to dedupe the data
1 parent cccc148 commit 3f2f5c8

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

scripts/jobs/parking/parking_permit_denormalisation_mc.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Code has been switched the use of the raw vrm and vrm update tables to the 480 raw tables
2222
2323
02/09/2024 - Create query from 'parking_permit_denormalisation'
24+
30/10/2024 - add code to remove the dupliacte records
2425
****************************************************************************************************************/
2526
/*** Obtain the Permits start/finish for FTA and renewals ***/
2627
With PermitStartFinishBEFORE as (
@@ -490,11 +491,13 @@
490491
A.permit_reference not like 'HYF%' AND
491492
A.permit_reference not like 'HYJ%' AND
492493
A.permit_reference not like 'HYE%' AND
493-
(renewal_start_date != '' OR renewal_end_date != ''))
494+
(renewal_start_date != '' OR renewal_end_date != '')),
494495
495496
/******************************************************************************************************************/
496497
/*** Finally output the data, WITH The VRM details **/
497-
SELECT
498+
/*** 30-10-2024 add code to remove the duplicates ***/
499+
Output as (
500+
SELECT
498501
A.permit_reference, A.application_date, A.forename_of_applicant, A.surname_of_applicant,
499502
A.email_address_of_applicant, A.primary_phone, A.secondary_phone, A.date_of_birth_of_applicant,
500503
A.blue_badge_number, A.blue_badge_expiry, A.start_date, A.end_date, A.approval_date,
@@ -519,22 +522,34 @@
519522
Else ''
520523
END as Fin_Year_Flag,
521524
/** Financial Year **/
522-
Fin_Year,
523-
524-
usrn,
525+
Fin_Year, usrn
526+
From Permits as A
527+
LEFT JOIN VRMDetails as B ON A.permit_reference = B.permit_reference AND A.vrm = B.vrm and B.row_num = 1
528+
LEFT JOIN CalendarFormat as F ON CAST(A.application_date as date) = date and F.row_num = 1
529+
LEFT JOIN LLPG_USRN as G ON A.uprn = G.uprn
530+
Where A.Rn = 1)
531+
532+
/*** Output the deduped data ***/
533+
SELECT
534+
permit_reference, application_date, forename_of_applicant, surname_of_applicant,
535+
email_address_of_applicant, primary_phone, secondary_phone, date_of_birth_of_applicant,
536+
blue_badge_number, blue_badge_expiry, start_date, end_date, approval_date,
537+
approved_by, approval_type, amount, payment_date, payment_method, payment_location,
538+
payment_by, payment_received, directorate_to_be_charged, authorising_officer,
539+
cost_code, subjective_code, permit_type, ordered_by, business_name, hasc_organisation_name,
540+
doctors_surgery_name, number_of_bays, number_of_days, number_of_dispensation_vehicles,
541+
dispensation_reason, uprn, address_line_1, address_line_2, address_line_3, postcode,
542+
cpz, cpz_name, status, quantity, vrm, associated_to_order, Live_Permit_Flag,
543+
Permit_Fta_Renewal, Latest_Permit_Status, cpz_code,
544+
make, model, fuel, engine_capactiy, co2_emission, foreign, lpg_conversion, VRM_record_created,
545+
is_motorcycle, Fin_Year_Flag, Fin_Year, usrn,
525546
526-
--current_timestamp as ImportDateTime,
527-
528547
format_datetime(current_date, 'yyyy') AS import_year,
529548
format_datetime(current_date, 'MM') AS import_month,
530549
format_datetime(current_date, 'dd') AS import_day,
531550
format_datetime(current_date, 'yyyyMMdd') AS import_date
532-
533-
From Permits as A
534-
LEFT JOIN VRMDetails as B ON A.permit_reference = B.permit_reference AND A.vrm = B.vrm and B.row_num = 1
535-
LEFT JOIN CalendarFormat as F ON CAST(A.application_date as date) = date and F.row_num = 1
536-
LEFT JOIN LLPG_USRN as G ON A.uprn = G.uprn
537-
Where A.Rn = 1
551+
FROM Output
552+
WHERE R1 = 1
538553
"""
539554

540555
create_update_table_with_partition(

0 commit comments

Comments
 (0)