If you need to speed up the query, you need to remove the select subsector on line 3. To still have this count, you can reattach it again in the from clause with the exact parameters that you used at the beginning. Here's how it should look:
SELECT t1.date, t1.asset_id, t1.name, COUNT(t3.asset_id) AS 'dailyCount', MIN(CONCAT(t2.date, ' ', t2.time)) AS 'firstAir', MAX(CONCAT(t2.date, ' ', t2.time)) AS 'lastAir', ROUND(TIMESTAMPDIFF( MINUTE, MIN(CONCAT(t2.date, ' ', t2.time)), MAX(CONCAT(t2.date, ' ', t2.time)) ) / 60) as 'rotationSpan' FROM air_video AS t1 INNER JOIN air_video AS t2 ON (t1.asset_id = t2.asset_id) INNER JOIN air_video AS t3 ON (t2.asset_id = t3.asset_id AND t3.date = t1.date) WHERE t1.status NOT IN ('bumpers', 'clock', 'weather') AND t1.date BETWEEN '2012-04-01' AND '2012-04-30' GROUP BY t1.asset_id, t1.date HAVING `rotationSpan` > 72 OR `dailyCount` > 24 ORDER BY `date` ASC, `rotationSpan` DESC, `dailyCount` DESC
Since t2 is not date bound, you are obviously looking at the whole table, not the date range.
Edit: Due to the large number of date bindings, the query still worked too slowly. Then I took a different approach. I created 3 views (which you can obviously combine into a regular query without views, but I like the query of the final result more)
- T1 -
CREATE VIEW t1 AS select date,asset_id,name from air_video where (status not in ('bumpers','clock','weather')) group by asset_id,date order by date;
- T2 -
CREATE VIEW t2 AS select t1.date,t1.asset_id,t1.name,min(concat(t2.date,' ',t2.time)) AS 'firstAir',max(concat(t2.date,' ',t2.time)) AS 'lastAir',round((timestampdiff(MINUTE,min(concat(t2.date,' ',t2.time)),max(concat(t2.date,' ',t2.time))) / 60),0) AS 'rotationSpan' from (t1 join air_video t2 on((t1.asset_id = t2.asset_id))) group by t1.asset_id,t1.date;
- T3 -
CREATE VIEW t3 AS select t2.date,t2.asset_id,t2.name,count(t3.asset_id) AS 'dailyCount',t2.firstAir,t2.lastAir,t2.rotationSpan AS rotationSpan from (t2 join air_video t3 on(((t2.asset_id = t3.asset_id) and (t3.date = t2.date)))) group by t2.asset_id,t2.date;
From there, you can simply run the following query:
SELECT date, asset_id, name, dailyCount, firstAir, lastAir, rotationSpan FROM t3 WHERE date BETWEEN '2012-04-01' AND '2012-04-30' AND ( rotationSpan > 72 OR dailyCount > 24 ) ORDER BY date ASC, rotationSpan DESC, dailyCount DESC