Postgres SQL, as run
select case when publisher_name is not null and publisher_name is distinct from invoice_issuer_name then publisher_name else provider_name end as service_provider_name,
invoice_issuer_name as invoice_issuer_name,
billing_period_start as billing_period_start,
billing_period_end as billing_period_end,
sum(billed_cost) as total_billed_cost,
sum(effective_cost) as total_effective_cost,
sum(effective_cost) - sum(billed_cost) as cost_basis_difference
from focus.cost_and_usage
where billing_period_start >= $1::timestamptz
and billing_period_end < $2::timestamptz
group by 1, invoice_issuer_name, billing_period_start, billing_period_end
having abs(sum(effective_cost) - sum(billed_cost)) > 0.01
order by abs(sum(effective_cost) - sum(billed_cost)) desc, service_provider_name, invoice_issuer_name
limit 500Parameters: $1 = billing_period_start, $2 = billing_period_end
Original FOCUS SQL
SELECT
ServiceProviderName,
InvoiceIssuerName,
BillingPeriodStart,
BillingPeriodEnd,
SUM(BilledCost) AS TotalBilledCost,
SUM(EffectiveCost) AS TotalEffectiveCost,
SUM(EffectiveCost) - SUM(BilledCost) AS CostBasisDifference
FROM focus_data_table
WHERE
BillingPeriodStart >= ? AND BillingPeriodEnd < ?
GROUP BY
ServiceProviderName,
InvoiceIssuerName,
BillingPeriodStart,
BillingPeriodEnd
HAVING
ABS(SUM(EffectiveCost) - SUM(BilledCost)) > 0.01