ORA-00937: 不是单组组函数

发布于 2024-10-31 02:29:42 字数 231 浏览 0 评论 0原文

SELECT MIN(retail)
FROM books
WHERE category = 'COMPUTER'

工作正常,但是当我在选择中包含标题时,例如:

SELECT MIN(retail), title
FROM books
WHERE category = 'COMPUTER'

它不工作。为什么?如何让它发挥作用?

SELECT MIN(retail)
FROM books
WHERE category = 'COMPUTER'

works fine, but when I include title in select like:

SELECT MIN(retail), title
FROM books
WHERE category = 'COMPUTER'

it doesn't. Why? How to make it work?

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

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

发布评论

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

评论(2

誰ツ都不明白 2024-11-07 02:29:42

里斯的答案是正确的,如果这就是您的意思,但您可能想要 title(s) where retail=MIN(retail),并且该措辞建议如何得到答案:

SELECT title, retail
FROM books
WHERE category = 'COMPUTER'
 AND retail = (SELECT MIN(retail) FROM books WHERE category = 'COMPUTER')

为了减少重复,您可以使用 WITH 子句(如果您使用的是最新版本的 SQL):

;WITH ComputerBooks AS (
  SELECT title, retail
  FROM books
  WHERE category = 'COMPUTER')
SELECT title, retail
FROM ComputerBooks
WHERE retail = (SELECT MIN(retail) FROM ComputerBooks)

我用来确认语法的示例。

Rhys's answer is correct, if that is what you mean, but you might have wanted the title(s) where retail=MIN(retail), and that wording suggests how to get that answer:

SELECT title, retail
FROM books
WHERE category = 'COMPUTER'
 AND retail = (SELECT MIN(retail) FROM books WHERE category = 'COMPUTER')

To reduce duplication you can use a WITH clause (if you're using a recent version of SQL):

;WITH ComputerBooks AS (
  SELECT title, retail
  FROM books
  WHERE category = 'COMPUTER')
SELECT title, retail
FROM ComputerBooks
WHERE retail = (SELECT MIN(retail) FROM ComputerBooks)

Sample I used to confirm syntax.

我要还你自由 2024-11-07 02:29:42

MIN 适用于一组记录,因此您需要告诉它您指的是哪组记录。

如果您的意思是为每个标题显示最低零售量,那么您需要:

SELECT MIN(retail), title FROM books
WHERE category = 'COMPUTER'
GROUP BY title

MIN applies to a group of records, so you need to tell it which group of records you mean.

If you mean for each title, show the minimum of retail, then you need:

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