SELECT MIN(retail)
FROM books
WHERE category = 'COMPUTER'
工作正常,但是当我在选择中包含标题时:
SELECT MIN(retail), title
FROM books
WHERE category = 'COMPUTER'
它没有。为什么?如何使它工作?
最佳答案
Rhys 的答案是正确的,如果这就是您的意思,但您可能想要 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)
Sample I used to confirm syntax.关于sql - ORA-00937 : not a single-group group function,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5591154/