-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new SQL model to calculate fleet rankings and earnings
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{ config(materialized='table') }} | ||
|
||
SELECT | ||
RANK() OVER (ORDER BY SUM(ap.fleet_payment) DESC) AS rank, | ||
f.address AS fleet_address, | ||
SUM(ap.fleet_payment) AS honey, | ||
SUM(ap.fleet_usd_payment) AS USD, | ||
COUNT(DISTINCT dp.payee_address) AS driver_count -- Count of unique driver addresses that earned rewards | ||
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 | ||
-- Join to identify drivers who earned rewards within the fleet | ||
INNER JOIN | ||
hivemapper.dbt_all_payments dp ON dp.trx_hash = ap.trx_hash AND dp.is_fleet = false | ||
INNER JOIN | ||
hivemapper.derived_addresses dda ON dda.derivedaddress = dp.payee_address | ||
GROUP BY | ||
f.address | ||
ORDER BY | ||
rank; |