SELECT a.* FROM (select company_id
,COALESCE(sum(total_amount),0) total_amount
from t_statistics
group by company_id
order by batch_date desc) a
LIMIT 0,20
先看一下分页的基本原理(我拿的是CSDN那个百万级数据库来测试!):SELECT * FROM `csdn` ORDER BY id DESC LIMIT 100000,2000耗时: 0.813ms分析:对上面的mysql语句说明:limit 100000,2000的意思扫描满足条件的102000行while(i<pageSize&&rs.next()){%>
<tr>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("username")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("nichen")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("email")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("add_date")%></td>
<td bgcolor="#FFFFFF" align="left"><a href="modify_member_info.jsp?ID=<%=rs.getInt("uid")%>">修改</a><a href="delete.jsp?ID=<%=rs.getInt("uid")%>">删除</a></td>
</tr>
<%
rs.next()
i++
}
--------------------改成-------------------------
while(i<pageSize&&!rs.isAfterLast()){
%>
<tr>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("username")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("nichen")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("email")%></td>
<td bgcolor="#FFFFFF" align="left"><%=rs.getString("add_date")%></td>
<td bgcolor="#FFFFFF" align="left"><a href="modify_member_info.jsp?ID=<%=rs.getInt("uid")%>">修改</a><a href="delete.jsp?ID=<%=rs.getInt("uid")%>">删除</a></td>
</tr>
<%
i++
}
看看
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)