简体   繁体   English

选择计数为零的行

[英]Select count giving zero rows

The table have 11 rows 该表有11行

Query 询问

SELECT COUNT(*) FROM `zars_all` ORDER BY id DESC LIMIT 9,9

Result 结果

Zero Rows, even there are two rows having id 10 and 11 零行,即使有两行ID为10和11

Query 询问

SELECT * FROM `zars_all` ORDER BY id DESC LIMIT 9,9

Result 结果

Two Rows having id 10 and 11 两行ID为10和11

I have tried using column names as value in Count but it does't help. 我尝试将列名用作Count中的值,但没有帮助。 Any help is appreciated and please tell me if I am doing anything wrong here. 感谢您的帮助,如果我做错了什么,请告诉我。

Your first sentence SELECT COUNT(*) returns an integer. 您的第一句话SELECT COUNT(*)返回一个整数。

That means that the trailing LIMIT 9,9 is setting a minimum of 9 elements and a maximum of 9 elements. 这意味着尾随的LIMIT 9,9会设置最少9个元素,最多9个元素。

Let's examine the LIMIT offset, count clause parameters: 让我们检查LIMIT offset, count子句参数:

The offset specifies the offset of the first row to return. 偏移量指定要返回的第一行的偏移量。
The count specifies the maximum number of rows to return. 计数指定要返回的最大行数。

Your offset is out of bounds, that is why you get no rows . 您的偏移量超出范围,这就是为什么没有行的原因

Please remove that and leave it like: 请删除它,然后将其保留为:

SELECT COUNT(*) FROM `zars_all` ORDER BY id DESC

Waqas, Waqas,
LIMIT cannot be applied directly along with COUNT instead change your query like LIMIT不能与COUNT一起直接应用,而是更改您的查询,例如

SELECT count(*) FROM (select * from zars_all limit 9,9) as a"**;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM