次のクエリは期待どおりに機能しています。ただし、データが選択されたサマリーテーブルが大きすぎます。クエリには時間がかかります。
SELECT s.date_time AS date_time,SUM(s.requests) AS sum_requests,SUM(s.impressions) AS sum_views,SUM(s.clicks) AS sum_clicks,SUM(s.conversions) AS sum_conversions,
SUM(s.total_revenue) AS sum_revenue,SUM(s.total_revenue) AS sum_spend,
SUM(s.total_basket_value) AS sum_bv,SUM(s.total_num_items) AS sum_num_items,SUM(s.total_pubrevenue) AS sum_pubrevenue
FROM ox_data_summary_ad_hourly AS s
INNER JOIN ox_banners AS d ON (d.bannerid=s.ad_id)
INNER JOIN ox_campaigns AS m ON (m.campaignid=d.campaignid)
INNER JOIN ox_clients AS a ON (a.clientid=m.clientid)
LEFT JOIN ox_zones AS z ON (z.zoneid=s.zone_id)
LEFT JOIN ox_affiliates AS p ON (p.affiliateid=z.affiliateid)
WHERE a.agencyid = 3 AND z.zone_type = 'application' AND z.delivery = 8
AND s.date_time>='2012-07-01 00:00:00' AND s.date_time<='2012-07-01 23:59:59'
GROUP BY date_time
結合を単純化する必要があります。すべての結合用の一時テーブルを作成してから、そのテーブルをベーステーブルに結合する方法はありますか。これは私がこれまでに試したことです。
drop table if exists test.helper;
create table test.helper
select d.network_type , d.is_network, d.bannerid, p.agencyid, z.zone_type, z.delivery , z.zoneid
FROM ox_banners as d
INNER JOIN ox_campaigns AS m ON (m.campaignid=d.campaignid)
INNER JOIN ox_clients AS a ON (a.clientid=m.clientid)
left JOIN ox_agency as oa ON (oa.account_id = a.clientid)
left JOIN ox_affiliates AS p ON (p.agencyid = oa.agencyid)
left JOIN ox_zones AS z ON (z.affiliateid = p.affiliateid);
alter table test.helper add key(bannerid, zoneid);
ただし、元のテーブルと結合すると、正しい結果は返されません。
SELECT s.ad_id, s.date_time AS date_time,SUM(s.requests) AS sum_requests,SUM(s.impressions) AS sum_views,SUM(s.clicks) AS sum_clicks,SUM(s.conversions) AS sum_conversions,
SUM(s.total_revenue) AS sum_revenue,SUM(s.total_revenue) AS sum_spend,
SUM(s.total_basket_value) AS sum_bv,SUM(s.total_num_items) AS sum_num_items,SUM(s.total_pubrevenue) AS sum_pubrevenue
FROM ox_data_summary_ad_hourly AS s
inner JOIN test.helper AS d ON (d.bannerid=s.ad_id )
where d.agencyid = 3 AND d.zone_type = 'application' AND d.delivery = 8 and s.date_time>='2012-07-01 00:00:00' AND s.date_time<='2012-07-01 23:59:59'
GROUP BY date_time