MySQL 计数获取所有行

发布于 2024-11-09 03:07:09 字数 1432 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2024-11-16 03:07:09

这不是聚合查询的工作方式。对一定范围的记录(满足 WHERE 子句条件的记录)进行计数,然后 HAVING 子句过滤掉计数小于 5 的任何内容。如果如果您想要对计数做出贡献的特定行,您可以尝试类似的操作

select * from
`Table`, 
(SELECT x,y,z, COUNT(AID) as total
   from `Table`
   where /* Some condition goes here */
   Having total >5) subqry
where subqry.x = Table.x
and subqry.Y = Table.Y
and subqry.Z = Table.Z

...当然,这假设 x,y,zTable 的唯一键。如果情况并非如此,那么这种方法可能行不通。

另外,您是否缺少 group by 子句?

That's not how aggregate queries work. The count is done over a range of records (whichever ones meet the conditions of the WHERE clause) and then the HAVING clause filters out anything with a count less than 5. If you want the specific rows that contributed to the count you might try something like

select * from
`Table`, 
(SELECT x,y,z, COUNT(AID) as total
   from `Table`
   where /* Some condition goes here */
   Having total >5) subqry
where subqry.x = Table.x
and subqry.Y = Table.Y
and subqry.Z = Table.Z

...of course, this assumes that x,y,z are a unique key for Table. If this is not the case, then this approach may not work.

Also, are you missing a group by clause?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文