SELECT count(traffic_id) FROM traffic WHERE traffic_enterTime >= date_sub(curdate(),interval 1 day) AND traffic_enterTime <= date_sub(curdate(),interval 0 day) UNION SELECT count(DISTINCT traffic_ip) FROM (SELECT * FROM traffic WHERE traffic_enterTime >= date_sub(curdate(),interval 1 day) AND traffic_enterTime <= date_sub(curdate(),interval 0 day)) as subfrom;
1
ckjianzhong7 OP SELECT count(traffic_id) FROM traffic WHERE traffic_enterTime >= date_sub(curdate(),interval 1 day) AND traffic_enterTime <= date_sub(curdate(),interval 0 day) UNION SELECT count(DISTINCT traffic_ip) FROM traffic WHERE traffic_enterTime >= date_sub(curdate(),interval 1 day) AND traffic_enterTime <= date_sub(curdate(),interval 0 day);
|
2
des 2019-03-30 18:35:00 +08:00
数据结构没有,有没有索引,数据量,EXPLAIN 都没有,你想怎么优化?
在 traffic_enterTime 加个索引先? |
3
murmur 2019-03-30 18:53:08 +08:00
没有 explain 你让我们对着你的帖子 explain 么
程序员也不是神啊 |
4
GGGG430 2019-03-30 19:48:19 +08:00 via iPhone
拆分为多个子 sql,不要在 sql 里用函数
|
5
gosleep 2019-03-31 14:22:32 +08:00 via iPhone
看过优化好像用 explain 返回的结果可以获取行数,搜一下…
|