declare rows_not_update int;
declare rows_update int;
declare rows_all int;
select count(id) into rows_all from cn;
select count(id) into rows_not_update from cn where 'update'=0; -- 寻找未更新的,假设其状态=0
set rows_update=rows_all-rows_notupdate;
select rows_update;
[Quote=引用 6 楼 WWWWA 的回复:]
用子查询试试,速度可能会提高
select count(id) from (SELECT ID FROM cn where `update`=1) A group by id
OR
select count(id) from (SELECT ID FROM cn where `update`=1) A
[/Quote]
两个索引都用到了
用子查询试试,速度可能会提高
select count(id) from (SELECT ID FROM cn where `update`=1) A group by id
OR
select count(id) from (SELECT ID FROM cn where `update`=1) A
select count(id) from cn where `update`=1 group by id
试试
OR
select count(id) from (SELECT ID FROM cn where `update`=1) A group by id
OR
select count(id) from (SELECT ID FROM cn where `update`=1) A