WHERE 子句中的 MAX()
以下 sql,在 WHERE 子句中使用 MAX 聚合函数,不起作用:
SELECT
ID,
title,
relevance
FROM
myTable
WHERE
(relevance <= MAX(relevance)/2)
任何人都可以指出我正确的方向吗? myTable 是临时表,因此无法使用子查询再次引用。谢谢!
The following sql, with the MAX aggregrate function in the WHERE clause, does not work:
SELECT
ID,
title,
relevance
FROM
myTable
WHERE
(relevance <= MAX(relevance)/2)
Can anyone point me in the right direction? myTable is a temporary table, so cannot be referenced again using a sub-query. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
愿这有帮助
May this help
尝试使用 子查询
另一种方式使用 like
try using sub query
another way using having like
您需要使用子查询
You need to use a subquery
你应该能够做这样的事情。 (未经测试,如果这不能按预期工作,请告诉我。)
常见 MySQL 查询,获取一些很好的代码示例。查找组内配额(每组前 N 个),了解如何在查询中使用变量的示例,如上所示。
You should be able to do something like this. (Untested, so please let me know if this doesn't work as expected.)
Common MySQL Queries for some good code examples. Look for Within-group quotas (Top N per group) for an example of how to use variables in a query as shown above.
naresh提到的使用变量的方法是查询数据库的好方法,
因为它可以轻松理解查询。
the method to use a variable which is mentioned by naresh is a good way to query the database,
as it creates an ease in understanding the queries.
仍应返回与以前相同的行数,因为“A”只有一行。
Should still give you back the same number of rows as before, as "A" has only one row.