本文介绍了ORA-00937:不是单组分组功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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?
推荐答案
如果这是您的意思,Rhys的回答是正确的,但是您可能希望title
出现在retail=MIN(retail)
位置,并且该措辞表明了这一点.如何获得答案:
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')
要减少重复,可以使用WITH
子句(如果使用的是SQL的最新版本):
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)
这篇关于ORA-00937:不是单组分组功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!