jkvirgin of Offer Space
9/11/2019 - 4:57 PM

Query - Twilio Billing by Client

SELECT twilio_usage_log.client_id                        as 'Corporate Client Id (Parent Client Id)',
       brands.clientnames,
       brands.brands,
       sum(price)
from twilio_usage_log
left join (
  select
    client_id,
    GROUP_CONCAT(DISTINCT brands.name separator ', ') as brands,
    GROUP_CONCAT(DISTINCT brands.client_name separator ', ') as clientnames
  from brands
  group by client_id
) as brands on brands.client_id = twilio_usage_log.client_id
where category = 'totalprice'
  and startDate >= '2020-03-02'
  and startDate <= '2020-03-08'
group by twilio_usage_log.client_id;