子句的order by没有用去掉,改为: select S.STATION_NAME AS station_name, (select E.ID from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum=1 ) AS chargeId from OM_BASE_STATION S 试试
--改为 Select S.STATION_NAME AS station_name, ( Select E.ID from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum<2 ) AS chargeId from OM_BASE_STATION S order by chargeId.ID desc
Select S.STATION_NAME AS station_name, ( Select E.ID from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum<2 ) AS chargeId, ( Select E.ADDR from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum<2 ) AS addr, from OM_BASE_STATION S order by chargeId,addr desc大哥你的那种方法可以,但是我还要加多个字段就不可行,帮帮忙,搞定给你100分,我在等待你的回复。
我不是要分的,很少像楼主这样写sql: -----------------------Select S.STATION_NAME AS station_name, ( Select E.ID from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum<2 ) AS chargeId, ( Select E.ADDR from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum<2 ) AS addr, from OM_BASE_STATION S order by chargeId,addr desc ----------------------- 你的那种方法可以,但是我还要加多个字段就不可行?我调试了一下这样的sql: select s.xh, s.xm, (select t1.ski_niuke_cd from abc121313_0 t1 where S.xh = t1.ski_niuke_cd and rownum < 2) as dd, (select t2.ord from abc121313_0 t2 where S.xh = t2.ski_niuke_cd and rownum < 2) as ddd, s.num from aa_test s order by dd, ddd desc 可以执行的,你把错误提示写出来!
select S.STATION_NAME AS station_name,
(select E.ID from OM_ELEC_DETAIL E where S.ID=E.BASE_ID and rownum=1 ) AS chargeId
from OM_BASE_STATION S 试试
Select S.STATION_NAME AS station_name,
( Select E.ID from OM_ELEC_DETAIL E
where S.ID=E.BASE_ID and rownum<2 ) AS chargeId
from OM_BASE_STATION S order by chargeId.ID desc
( Select E.ID from OM_ELEC_DETAIL E
where S.ID=E.BASE_ID and rownum<2 ) AS chargeId,
( Select E.ADDR from OM_ELEC_DETAIL E
where S.ID=E.BASE_ID and rownum<2 ) AS addr,
from OM_BASE_STATION S order by chargeId,addr desc大哥你的那种方法可以,但是我还要加多个字段就不可行,帮帮忙,搞定给你100分,我在等待你的回复。
-----------------------Select S.STATION_NAME AS station_name,
( Select E.ID from OM_ELEC_DETAIL E
where S.ID=E.BASE_ID and rownum<2 ) AS chargeId,
( Select E.ADDR from OM_ELEC_DETAIL E
where S.ID=E.BASE_ID and rownum<2 ) AS addr,
from OM_BASE_STATION S order by chargeId,addr desc
-----------------------
你的那种方法可以,但是我还要加多个字段就不可行?我调试了一下这样的sql:
select s.xh,
s.xm,
(select t1.ski_niuke_cd
from abc121313_0 t1
where S.xh = t1.ski_niuke_cd
and rownum < 2) as dd,
(select t2.ord
from abc121313_0 t2
where S.xh = t2.ski_niuke_cd
and rownum < 2) as ddd,
s.num
from aa_test s
order by dd, ddd desc
可以执行的,你把错误提示写出来!