SQL ORA-01791: 不是 SELECTed 表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31691470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-01791: not a SELECTed expression
提问by drup
I need to fetch details from DB. Any thing wrong in my code?
我需要从数据库中获取详细信息。我的代码有什么问题吗?
SELECT DISTINCT FNAME, LNAME, MEMBERORG, DAYCOUNT, TIMESTAMP, COUNT(FNAME) AS total,(SELECT COUNT(*) FROM REPORT_VIEW_PAGE) AS tot
FROM REPORT_VIEW_PAGE
WHERE ID = '68' AND TYPE = 'node'
GROUP BY FNAME, LNAME, MEMBERORG, DAYCOUNT, TIMESTAMP
ORDER BY TITLE ASC
This giving me an error:
这给了我一个错误:
ORA-01791: not a SELECTed expression
01791. 00000 - "not a SELECTed expression"
*Cause:
*Action:
Error at Line: 6 Column: 10
回答by Shishir Kumar
The problem here is the ORDER BY
column TITLE
isn't selected in the DISTINCT
query. Since DISTINCT
is used, the SELECT
query will try to group the resultset
based on the selected columns.
这里的问题是未在查询中选择该ORDER BY
列。由于使用了,查询将尝试根据选定的列对进行分组。TITLE
DISTINCT
DISTINCT
SELECT
resultset
ORDER BY
column isn't selected here, it doesn't ensure the uniqueness on the resultset
and hence it fails to apply ORDER BY
.
ORDER BY
此处未选择列,它不能确保 上的唯一性resultset
,因此无法应用ORDER BY
。
回答by Piyushkumar Kachhadiya
SELECT DISTINCT FNAME, LNAME, MEMBERORG, DAYCOUNT, TIMESTAMP, total, tot
FROM
(
SELECT DISTINCT FNAME, LNAME, MEMBERORG, DAYCOUNT, TIMESTAMP, COUNT(FNAME) AS total,(SELECT COUNT(*) FROM REPORT_VIEW_PAGE) AS tot
FROM REPORT_VIEW_PAGE
WHERE ID = '68' AND TYPE = 'node'
GROUP BY FNAME, LNAME, MEMBERORG, DAYCOUNT, TIMESTAMP
ORDER BY TITLE ASC
)