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,
sub_account_id as sub_account_id,
sub_account_name as sub_account_name,
sum(billed_cost) as total_billed_cost
from focus.cost_and_usage
where charge_category = 'Usage'
and charge_period_start >= $1::timestamptz
and charge_period_end <= $2::timestamptz
and case when publisher_name is not null and publisher_name is distinct from invoice_issuer_name then publisher_name else provider_name end = $3::text
and sub_account_id = $4::text
group by 1, sub_account_id, sub_account_name
order by total_billed_cost desc nulls lastParameters: $1 = period_start, $2 = period_end, $3 = service_provider_name, $4 = sub_account_id
Original FOCUS SQL
SELECT
ServiceProviderName,
SubAccountId,
SubAccountName,
SUM(BilledCost) AS TotalBilledCost
FROM focus_data_table
WHERE ChargeCategory = 'Usage'
AND ChargePeriodStart >= ? and ChargePeriodEnd <= ?
AND ServiceProviderName = ?
AND SubAccountId = ?
GROUP BY
ServiceProviderName,
SubAccountId,
SubAccountName