我有一个超过1000万行的统计表。
这是我的疑问:
SELECT
SUM(s.requests) as requests,
SUM(s.impression) as impression,
SUM(s.bad_requests) as bad_requests,
SUM(s.empty_body) as empty_body,
SUM(s.bad_vast) as bad_vast,
SUM(s.exceptions) as exceptions,
SUM(s.midpoint) as midpoint,
SUM(s.complete) as complete,
SUM(s.click) as click,
SUM(s.start) as start,
SUM(s.creativeview) as creativeview,
(SUM(s.impression) / SUM(s.requests)) * 100 as req_fill,
(SUM(s.click) / SUM(s.impression)) * 100 as ctr,
(SUM(s.complete) / SUM(s.impression)) * 100 as completion,
SUM(s.media_cost) as media_cost,SUM(s.revenue) as revenue,
SUM(s.revenue) - SUM(s.media_cost) as profit_net,((SUM(s.revenue) - SUM(s.media_cost)) / SUM(s.revenue)) * 100 as margin_net
FROM
(
SELECT
SUM(t.requests) AS requests,
SUM(t.impression) AS impression,
SUM(t.bad_requests) AS bad_requests,
SUM(t.empty_body) AS empty_body,
SUM(t.bad_vast) AS bad_vast,
SUM(t.exceptions) AS exceptions,
SUM(t.midpoint) AS midpoint,
SUM(t.complete) AS complete,
SUM(t.click) AS click,
SUM(t.start) AS start,
SUM(t.creativeview) AS creativeview,
SUM(IF(p.rate_type = "0", (t.impression * p.fixed_rate) / 1000, (t.impression * d.rate) / 1000 * (p.percent_rate / 100))) as media_cost,
SUM((t.impression * d.rate) / 1000) as revenue
FROM 2017_Stats PARTITION (day49,day50,day51,day52,day53,day54,day55) t
JOIN Demands d ON d.id = t.demand_tag_id
JOIN Supplies p ON p.id = t.supply_tag_id
WHERE t.supply_tag_id IN (27,26,25,24,23,22,21,20,19,18,17,16,14,10,9,7,6,5,4,1)
) s
Mysql 5.7版本,查询速度很慢((
您能帮助简化查询吗?