Jump to content

Statistics query


Ryan Marks

Recommended Posts

I'm trying to capture data from Revive by way of a MySQL query that will be consumed by a client-facing statistics dashboard.  The data I'm interested in is Client name, Client ID (stored in Client Comments), Date, Total Impressions, Total Clicks, Affiliate name.

I've written the following query, but it takes a while to respond:

SELECT
    client.clientname AS `Client`
    , client.comments AS `Client ID`
    , DATE_FORMAT( CONVERT_TZ( STR_TO_DATE(stats.date_time, '%Y-%m-%d'), 'GMT', 'America/Chicago'), '%Y-%m-%d') AS `Date`
    , SUM( stats.`impressions` ) AS `Impressions`
    , SUM( stats.`clicks` ) AS `Clicks`
    , affiliate.name as 'Website'
FROM
    `ox_clients` client
    LEFT JOIN `ox_campaigns` campaign USING (clientid)
    LEFT JOIN `ox_banners` banner USING (campaignid)
    LEFT JOIN `ox_data_summary_ad_hourly` stats ON banner.bannerid = stats.ad_id
    LEFT JOIN `ox_zones` zone ON stats.zone_id = zone.zoneid
    LEFT JOIN `ox_affiliates` affiliate USING (affiliateid)
WHERE
    client.comments <> '' -- we only want clients with the comments field populated
    AND DATE_FORMAT( CONVERT_TZ( STR_TO_DATE(stats.date_time, '%Y-%m-%d'), 'GMT', 'America/Chicago'), '%Y-%m-%d') = DATE(NOW()) - INTERVAL 1 DAY
GROUP BY
    client.clientid
    , affiliate.name
    , DATE_FORMAT( CONVERT_TZ( STR_TO_DATE(stats.date_time, '%Y-%m-%d %H:%i:%s'), 'GMT', 'America/Chicago'), '%Y-%m-%d')
ORDER BY
    DATE_FORMAT( CONVERT_TZ( STR_TO_DATE(stats.date_time, '%Y-%m-%d %H:%i:%s'), 'GMT', 'America/Chicago'), '%Y-%m-%d')

The above query took 48 seconds to run.  I ran an explain which is below.

image.png?pub_secret=2168fe9517

Is there a query I can use that will help me get to the dimensions and metrics I've mentioned above?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...