select i.card_id,
(select m.names from
(select rownum as r ,t.code_detail,d.names from infectiondetail t, infection_steps d where t.code_detail = d.code and t.infection_cardid = i.card_id order by t.dt_start desc,t.addtime desc) m
where m.r<2
) diseaasestageName
from infectioncard i
where i.card_id ='-59052'
结果:card_id diseaasestageName
-59052 死亡期select i.card_id,
(select m.names from
(select rownum as r ,t.code_detail,d.names from infectiondetail t, infection_steps d where t.code_detail = d.code and t.infection_cardid = '-59052' order by t.dt_start desc,t.addtime desc) m
where m.r<2
) diseaasestageName
from infectioncard i
where i.card_id ='-59052'结果:card_id diseaasestageName -59052 为什么前一个 的diseaasestagename有值,后一个就没值呢??
SELECT i.card_id,
(SELECT rownum, m.names
FROM (SELECT t.code_detail, d.names
FROM infectiondetail t, infection_steps d
WHERE t.code_detail = d.code AND
t.infection_cardid = i.card_id
ORDER BY t.dt_start DESC, t.addtime DESC) m
WHERE rownum < 2) diseaasestageName
FROM infectioncard i
WHERE i.card_id = '-59052';SELECT i.card_id,
(SELECT rownum, m.names
FROM (t.code_detail, d.names FROM infectiondetail t, infection_steps d WHERE
t.code_detail = d.code AND t.infection_cardid = '-59052' ORDER BY t.dt_start DESC,
t.addtime DESC) m
WHERE rownum < 2) diseaasestageName
FROM infectioncard i
WHERE i.card_id = '-59052'
http://hi.baidu.com/%B1%BF%B1%BF%D0%DCvs%D0%A1%BE%AB%C1%E9/blog/item/a3ed0622a5b26d48935807c3.html