日期:2014-05-17  浏览次数:21124 次

SQL SERVER 中的top语句使用oracle如何写?
Talbe TA 

id name job

Table TB

id job num 

SQL SERVER语法:

select *,(select top 1 num from TB where job=TA.job) from TA 

求教如何转为oracle 语句

------解决方案--------------------
select id, name, job from TA where id in
(select id from (select id from TB order by num desc) where rownum=1);

------解决方案--------------------
Talbe TA

id name job

Table TB

id job num
select [列名,列名],(select num from TB where job=TA.job and rownum <2) from TA
用 rownum 不是那样回报错要写成
select a,b,c,d,(select 列 from 表)

------解决方案--------------------
select id, name, job from TA where job in
(select job from TB) where rownum<2;

------解决方案--------------------
Key Words---RowNum
------解决方案--------------------
SQL code

select t1.*,t2.num
from TA t1,
(select job,num from TB a where a.rowid = (select max(b.rowid) from TB b where b.job=a.job)) t2
where t1.job=t2.job