This query calculates the lifetime value and number of deals per company
SELECT cp.company_name
, coalesce(SUM(d.closed_amount_in_home_currency), 0) AS LTV
, coalesce(COUNT(d.deal_id), 0) AS LTD
FROM hubspot_companies_consolidated cp
LEFT JOIN hubspot_deals_companies dc ON dc.company_id = cp.company_id
INNER JOIN hubspot_deals_consolidated d ON d.deal_id = dc.deal_id
WHERE d.deal_stage = 'closedwon'
GROUP BY 1
ORDER BY 2 DESC, 3 DESC;
Column | Description |
---|---|
company_name |
Company name. |
LTV |
Lifetime value. |
LTD |
Lifetime deals count. |