From 704732912a79d248e4146be679011a8dabbd872b Mon Sep 17 00:00:00 2001 From: Charles Billette Date: Tue, 17 Sep 2024 10:13:17 -0400 Subject: [PATCH] Refactor SQL query for revenue ranking This change updates the query to use `derived_addresses.address` instead of `fleets.address` and simplifies join conditions. The grouped column and join statements have been adjusted to improve query clarity and readability. --- dbt/hivemapper/models/example/dbt_driver_and_revenu.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dbt/hivemapper/models/example/dbt_driver_and_revenu.sql b/dbt/hivemapper/models/example/dbt_driver_and_revenu.sql index b85387f..001c148 100644 --- a/dbt/hivemapper/models/example/dbt_driver_and_revenu.sql +++ b/dbt/hivemapper/models/example/dbt_driver_and_revenu.sql @@ -2,10 +2,9 @@ select RANK() OVER(ORDER BY SUM(ap.fleet_payment) DESC) rank, - f.address, + da.address, sum(ap.fleet_payment) as honey, sum(ap.fleet_usd_payment) as USD -from hivemapper.fleets f - inner join hivemapper.derived_addresses da on da.address = f.address - inner join hivemapper.dbt_all_payments ap on ap.payee_address = da.derivedaddress -group by f.address \ No newline at end of file +from hivemapper.dbt_all_payments ap + inner join hivemapper.derived_addresses da on da.derivedaddress = ap.payee_address +group by da.address \ No newline at end of file