Mysql 动态分页SQL
set @strsql = concat( 'select sql_calc_found_rows * from receivedata ' ,' where 1=1 ' ); set @strsql=concat(@strsql,CASE IFNULL(@openid, '') WHEN '' THEN ' and FromUserName=FromUserName ' ELSE CONCAT(' and FromUserName=''', @openid,''' ') END); set @strsql=concat(@strsql,' order by id desc '); set @strsql=concat(@strsql,' limit ',@startRow,@pageSize,'; '); prepare PageSql from @strsql; execute PageSql ; select @TotalRecords = found_rows();//必需是inputoutput deallocate prepare PageSql;