方法一(存储过程实现):

 

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
  • 2021-11-29
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-01-12
相关资源
相似解决方案