这不是聚合查询的工作方式。对一定范围的记录(满足 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
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.
发布评论
评论(1)
这不是聚合查询的工作方式。对一定范围的记录(满足 WHERE 子句条件的记录)进行计数,然后 HAVING 子句过滤掉计数小于 5 的任何内容。如果如果您想要对计数做出贡献的特定行,您可以尝试类似的操作
...当然,这假设
x,y,z
是Table
的唯一键。如果情况并非如此,那么这种方法可能行不通。另外,您是否缺少
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 theHAVING
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...of course, this assumes that
x,y,z
are a unique key forTable
. If this is not the case, then this approach may not work.Also, are you missing a
group by
clause?