小编典典

ORA-00937:不是单组分组功能

sql

SELECT MIN(retail)
FROM books
WHERE category = ‘COMPUTER’

效果很好,但是当我在select中包含标题时,例如:

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

没有。为什么?如何使其运作?


阅读 168

收藏
2021-03-23

共1个答案

小编典典

如果那是您的意思,Rhys的答案是正确的,但是您可能想在title()中使用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)
2021-03-23