我的程序中,会接受到一条查询SQL语句(以SELECT开头)    有可能是比较复杂的查询语句而我的程序的功能是返回这个查询语句的结果数量
条件1:不能是先把这个SQL执行了  再通过count($rs)这样的办法获得,需要直接通过SQL计算出条件2:因为无法预知这个SQL要查询的表名、列名
最好是可以类似加工SQL语句   比如  :select count(select account_id,account_name from jj_account)         这个可行不通,我只是举个例子或者select count(*) from (select account_id,account_name from jj_account)    当然这个也是无效的  

解决方案 »

  1.   

    写个存储过程set @mycnt = 0;
    select max(rownum) from (select (@mycnt := @mycnt + 1) as rownum ,yourcol from yourtable) as tmp;
    其中max(rownum)即为你所求
      

  2.   

    select count(*) from (select account_id,account_name from jj_account) as tmp;你的sql 加上 as tmp就可以运行了
      

  3.   

    在SELECT后面加上SQL_CALC_FOUND_ROWS,然后执行完了用FOUND_ROWS()取回行数?