sql – ORA-00937:不是单组组功能

前端之家收集整理的这篇文章主要介绍了sql – ORA-00937:不是单组组功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
SELECT MIN(retail)
FROM books
WHERE category = 'COMPUTER'

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

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

它没有.为什么?如何使它工作?

解决方法

Rhys的答案是正确的,如果这是你的意思,但你可能想要零售= MIN(零售)的标题,并且该措辞建议如何得到答案:
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.

原文链接:https://www.f2er.com/mssql/76566.html

猜你在找的MsSQL相关文章