方法一(存储过程实现):
begin
DECLARE cnt INT DEFAULT 0;
select count(*) into cnt from user;
set cnt = round(cnt*0.9)-1;
select * from user limit cnt, 1;
end
方法二(直接查询,,只有查询权限的时候可以考虑):
这种方法也是解决mysql limit后面不支持变量的问题
SELECT COUNT(*) INTO @cnt FROM cmb_loading_count_20141013 WHERE ver>=1003002251;
SET @cnt = ROUND(@cnt*0.9)-1;
SET @stmt = ‘select loading_time from cmb_loading_count_20141013 where ver>=1003002251 order by loading_time asc limit ?,?‘;
PREPARE s1 FROM @stmt;
SET @end = 1;
EXECUTE s1 USING @cnt,@end;
DEALLOCATE PREPARE s1;
参考:
http://www.2cto.com/database/201309/241093.html