Jump to content
Ryan Marks

Statistics query

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:

    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'
    `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)
    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
    , affiliate.name
    , DATE_FORMAT( CONVERT_TZ( STR_TO_DATE(stats.date_time, '%Y-%m-%d %H:%i:%s'), 'GMT', 'America/Chicago'), '%Y-%m-%d')
    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.


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

Share this post

Link to post
Share on other sites

Hi Ryan,

I haven't actually run your query, so, just to clarify - is the issue that your query isn't returning the data you want (and you need help getting the right info), or is the issue that it takes a while to return (and you need help making it faster)?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now