mysql – SQL限制组数

我试图创建一个简单的分页,但它似乎无法限制结果的数量.SELECT * FROM visits GROUP by clientID ORDER BY date LIMIT $from, $to 我想只获得每个客户的第一次访问(按时间顺序)并对结果进行分页.如果我使用$from = 6,$to = 12进行此查询,则返回8行而不是7行.

我试图创建一个简单的分页,但它似乎无法限制结果的数量.

SELECT * FROM visits GROUP by clientID ORDER BY 'date' LIMIT $from,$to

我想只获得每个客户的第一次访问(按时间顺序)并对结果进行分页.

如果我使用$from = 6,$to = 12进行此查询,则返回8行而不是7行.

我做错了什么?

最佳答案
来自MySQL的LIMIT条款文档

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments,which must both be nonnegative integer constants (except when using prepared statements).

With two arguments,the first argument specifies the offset of the first row to return,and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1).

当你选择$from 6和$to 12;你不是从6到12选择;你将从$1 = 7开始选择12行.

作者: dawei

【声明】:西安站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部