select AA.*, (select ccc from BB where BB.ryid=AA.ryid and rownum =1 order by SJ) as CCC
FROM AA order by AA.ryid asc
中间这句select ccc from BB where BB.ryid=AA.ryid and rownum =1 order by SJ有什么错呢?
谢谢~~
------解决方案--------------------
不知什么錯誤,可能子查詢里不能有order by ,但也可以這樣寫:
select AA.*,tt.ccc
from
AA,
(
select ccc,t.ryid from BB v,
(select min(sj) sj,ryid from BB group by ryid)t
where t.sj=v.sj and t.ryid=v.ryid
)tt
where AA.ryid=tt.ryid