简体   繁体   English

SQL计数未返回所有行,phpmyadmin添加LIMIT但未在查询中显示

[英]SQL count not return all rows, phpmyadmin add LIMIT but not show it in the query

I have a query: 我有一个查询:

select lr2.event_id as ce
from data_requests as lr2 
group by lr2.event_id, 

that returns 88 rows. 返回88行。 Then I tried the following: 然后我尝试了以下方法:

select count(lr2.event_id) as cc, lr2.event_id as ce 
from data_requests as lr2 
group by lr2.event_id

but it only returned 25 rows, so I am really puzzled, where did other 63 rows go. 但是它只返回了25行,所以我很困惑,其他63行又去了哪里。

I tried it in sqlfiddle, it seems to work correctly, but on my server it just doesn't, so it must be a setting or something... Feels like the server calculates the count after it select a subset of all group results. 我在sqlfiddle中尝试了一下,它似乎可以正常工作,但是在我的服务器上却无法正常工作,因此它必须是设置或类似的东西。 weird. 奇怪的。

if you want to count the number of rows for each lr2.event_id you must use count(*) , not count(lr2.event_id) . 如果要计算每个lr2.event_id的行数,则必须使用count(*) ,而不是count(lr2.event_id) Remember, you are counting rows. 请记住,您正在计数行。

Function of GROUP BY GROUP BY的功能

The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical/similar/equal data into groups. SQL GROUP BY子句与SELECT语句配合使用,将相同/相似/相等的数据排列到组中。

Demonstration 示范
If I have table like below, then 1st query will give same output as table definition: 如果我有如下表,则第一个查询将给出与表定义相同的输出:

ce
--
1
2
3
4
5

And 2nd query will give output as, 第二查询将输出为

cc |ce
--- ---
1   1
1   2
1   3
1   4
1   5

Since, all are distinct in Table, I got 5 rows! 由于表中的所有内容都distinct ,所以我得到了5行! but If some ce values are repetitive as, 但是如果某些ce值重复为,

ce
--
1
2
1
2
2

then, 2nd query will give output as: 然后,第二个查询将给出输出为:

cc |ce
--- ---
2   1
3   2

And here If I get shocked where did other 3 rows go ? 在这里,如果我感到震惊,其他3行又去了哪里 Then I need to study! 那我需要学习! Of course, it's a spoon feeding! 当然,这是汤匙喂食! OP needs to study about GROUP BY in SQL. OP需要研究SQL中的GROUP BY

我的不好,这似乎是phpmyadmin问题,我在phpmyadmin中运行查询,并且它在每个查询的末尾自动添加了一个限制

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

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