select (case when a.TOTALNETUNIT is not null then
( select c.TOTALNETUNIT from FND_DERNAV c where c.SECUCODE=a.secucode and rownum=1 order by c.enddate desc )
else a.totalnetunit
end) as MyColumn
from FND_DERNAV a inner join FND_DAILYQUOTE b on a.SECUCODE=b.secucode and b.TRADINGDAY=a.ENDDATE
"报ORA-00907 缺失右括号“求解 我这条sql为什么会出错呢?
(select 'a' a from dual)
else 'b'
end) c
from dual是不是括号不是英文格式?
还真没注意 order by 和rownum合用... 如果要排序取一行只有嵌套或者over函数了
是没报错 但是取的数据不是你想要的 相当于select* from FND_DERNAV where rownum=1 也就是排序完全没起到作用如果要取排序后的 要先排序再取select * from
(select *
from FND_DERNAV
order by enddate desc)
where rownum=1
when a.TOTALNETUNIT is not null then
(select c.TOTALNETUNIT
from FND_DERNAV c
where c.SECUCODE = a.secucode and rownum = 1
order by c.enddate desc)
else
a.totalnetunit
end) as MyColumn
from FND_DERNAV a
inner join FND_DAILYQUOTE b
on a.SECUCODE = b.secucode
and b.TRADINGDAY = a.ENDDATE应该是我标红的地方出错,你可以用在这个地方设置一个常量试试。
Oracle 好像只能套一个括号,套多了就失效了~~不知道我的想法是不是对的
select a.secucode, (case when a.TOTALNETUNIT is not null then
(select TOTALNETUNIT from ( select c.TOTALNETUNIT from FND_DERNAV c where c.SECUCODE=a.secucode order by c.enddate desc) where rownum=1)
else a.totalnetunit
end) as MyColumn
from FND_DERNAV a inner join FND_DAILYQUOTE b on a.SECUCODE=b.secucode and b.TRADINGDAY=a.ENDDATE
红色的部分 就不能识别了~ 我想到一种方法 但是速度实在不行