-- dbt Gold Regional Waste Revenue & Compliance Mart SELECT region_zone, facility_type, waste_category, COUNT(order_id) AS total_orders, COUNT(DISTINCT facility_id) AS active_facilities_count, COUNT(DISTINCT generator_company) AS active_generators_count, ROUND(SUM(volume_ton), 2) AS total_waste_volume_ton, ROUND(SUM(total_order_amount), 2) AS total_gross_revenue, ROUND(AVG(total_order_amount / NULLIF(volume_ton, 0)), 2) AS avg_revenue_per_ton, COUNT(CASE WHEN environmental_compliance_status = 'COMPLIANT' THEN 1 END) AS compliant_orders_count, CURRENT_TIMESTAMP AS mart_refreshed_at FROM {{ ref('silver_waste_manifest_enriched') }} GROUP BY region_zone, facility_type, waste_category ORDER BY total_waste_volume_ton DESC