[英]Inner Query For Oracle is not working?
我有2个表table1和table2。 我想从两个表中获取数据。 查询是
SELECT tb2.tdn
,tb2.nrn
,tb2.id
,tb2.dat
,tb2.mcheck
,tb2.info
,tb2.edrf
, (SELECT count(*)
from table1 tb1
where tb1.id = 'ftam'
and tb1.tdn = tb2.tdn
and (tb1.display = 'Y' OR tb1.display = 'y') ) as history
from (select rownum rnum
,table2.*
FROM (SELECT *
FROM table2
WHERE id = 'ftam'
and (display = 'Y' OR display = 'y')
ORDER BY dat DESC ) table2 tb2
where rownum <= 50 )
WHERE rnum > 0
展示
SQL Error [907] [42000]: ORA-00907: missing right parenthesis
ORA-00907: missing right parenthesis
查询有什么问题? 我已经在MySQL中实现了它,但是当我将查询更改为Oracle时,它显示了错误。
谢谢
为了清楚起见,更改发布布局显示此行是当前的问题:
ORDER BY dat DESC ) table2 tb2
您需要一个别名,而不是两个。 所以应该
ORDER BY dat DESC ) table2
您还需要在外部嵌套查询上放置一个别名:
(select rownum rnum
,table2.*
FROM (SELECT *
FROM table2
WHERE id = 'ftam'
and (display = 'Y' OR display = 'y')
ORDER BY dat DESC ) table2
where rownum <= 50 ) tb2
您的查询需要大量改进,如果您告诉我们您要做什么,我们也许可以帮助您构建查询。
在查询中id是一个字符,最好是数字。 您添加条件='y'或='Y',可以添加较低/较高的功能。
这是解决您的查询的建议。
select rownum rnum, table2.*
FROM table2
WHERE id = 'ftam'
and lower(display) = 'Y' and rownum <= 50
ORDER BY dat DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.