问题是这样的:
想要从一个有很多条记录的tableA里查找符合条件col = cond1 的记录条数不仅如此,要求当满足条件的记录数到达aValue时,就让查询立即返回,(因为对程序来说已经足够了)
而不要再把整个表搜个遍;
如果搜遍了整个表,符合条件的记录数也没有达到aValue时,就返回总的满足条件的记录数

解决方案 »

  1.   

    用SQL语句不能做到,用存储过程,你要查找的是单一字段?
      

  2.   

    用游标+WHILE DO,累加判断,速度比较慢,为什么要这样要求?
      

  3.   

    调整一下思路:
    如只是单一字段
    create table newtemp as
    select * from tt limit aValue;
    select count(*) from newtemp;
    如满足条件记录数>aValue,则只返回aValue,如<aValue,则返回实际记录数
      

  4.   

    try:
    create table newtemp as
    select * from tt where .... limit aValue;
    select count(*) from newtemp;
    如满足条件记录数>aValue,则只返回aValue,如 <aValue,则返回实际记录数
      

  5.   

    select count(t.*) from (select * from tableA where col = cond1 limit aValue) t这样应该会好一点
      

  6.   

    如果是简单sql,最后限制limit。
    或是用存储过程,用游标实现。如果是复杂sql,就不知道了。
      

  7.   

    这样吧。刚好能满足你的要求。
    select sql_calc_found_rows * from tableA where col = cond1 limit aValue;
    select found_rows() into @cnt;
    然后你就可以判断@cnt的值和aValue;