gpt4 book ai didi

sql - 带有子查询的 Oracle 选择

转载 作者:行者123 更新时间:2023-12-04 10:41:26 26 4
gpt4 key购买 nike

你能帮我下一个 oracle sql 查询吗?

SELECT "NEWS"."NEWSID" as ID,
"NEWS"."SLUG",
"NEWS_TRANSLATION".*,
(SELECT FILENAME FROM NEWS_MEDIA WHERE NEWSID = ID AND rownum <= 1 ORDER BY POSITION ASC) as FILENAME
FROM "NEWS"
INNER JOIN "NEWS_TRANSLATION" ON NEWS.NEWSID = NEWS_TRANSLATION.NEWSID
WHERE (NEWS.PUBLISH = 1) AND (NEWS_TRANSLATION.LANG = :lang)
ORDER BY "NEWS"."NEWSID" DESC;

当我执行此查询时出现错误
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 74

最佳答案

尝试这个:

SELECT "NEWS"."NEWSID" as ID,
"NEWS"."SLUG",
"NEWS_TRANSLATION".*,
(SELECT * FROM (SELECT FILENAME FROM NEWS_MEDIA WHERE NEWSID = ID ORDER BY POSITION ASC) WHERE rownum = 1) as FILENAME
FROM "NEWS"
INNER JOIN "NEWS_TRANSLATION" ON NEWS.NEWSID = NEWS_TRANSLATION.NEWSID
WHERE (NEWS.PUBLISH = 1) AND (NEWS_TRANSLATION.LANG = :lang)
ORDER BY "NEWS"."NEWSID" DESC;

当您同时使用“order by”和“rownum”时,您需要先对它们进行排序并查找第一条记录。

关于sql - 带有子查询的 Oracle 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11794242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com