17,377
社区成员
发帖
与我相关
我的任务
分享
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
select * from
(select *
from FND_DERNAV
order by enddate desc)
where rownum=1
and rownum=1 order by c.enddate desc
的用法就有问题,rownum是个伪列,是先于order by子句执行的,所以你加个按结束日期排序毫无意义,不信你把desc改成asc看看,结果是一样的。
select (case when 'a'='a' then
(select 'a' a from dual)
else 'b'
end) c
from dual
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