CREATE TABLE event_data (utc_time TIMESTAMP NOT NULL, creative_id INTEGER NOT NULL, cost DECIMAL, campaign_id INTEGER NOT NULL, advertiser_id INTEGER NOT NULL, site_id INTEGER NOT NULL, is_impression INTEGER NOT NULL, is_clickthrough INTEGER NOT NULL, is_conversion INTEGER NOT NULL); SELECT site_id, COUNT(*) AS records, SUM(is_impression) AS impressions, SUM(is_clickthrough) AS clicks, SUM(is_conversion) AS conversions, SUM(cost) AS cost FROM event_data GROUP BY site_id; SELECT advertiser_id, COUNT(*) AS records, SUM(is_impression) AS impressions, SUM(is_clickthrough) AS clicks, SUM(is_conversion) AS conversions, SUM(cost) AS cost FROM event_data GROUP BY advertiser_id; SELECT advertiser_id, TRUNCATE(DAY,utc_time) AS utc_day, COUNT(*) AS records, SUM(is_impression) AS impressions, SUM(is_clickthrough) AS clicks, SUM(is_conversion) AS conversions, SUM(cost) AS spent FROM event_data GROUP BY advertiser_id, TRUNCATE(DAY,utc_time); SELECT creative_id AS ad, SUM(cost) AS cost FROM event_data GROUP BY creative_id ORDER BY cost DESC LIMIT 10;