database - SQL Subquery to get first record -
i need execute query below.
select to_char(rownum), a.name, b.order, (select * ( select round(last_order_amount,5) orders id=a.id , request_level='n' order o_date desc) rownum =1) amount table1 left join table2 b on a.type_code = b.entity_type
but gives me a.id invalid error in oracle. need first record inner query return multiple records.
can please let me know how can bind these tables achieve goal.
thank in advance.
you can rewrite subquery using with
clause, not sure on syntax should following.
with amountquery ( select id ,round(last_order_amount, 5) amountvalue ,row_number() on ( order o_date desc ) rn orders request_level = 'n' ) select to_char(rownum) ,a.name ,b.order ,c.amountvalue table1 left join table2 b on a.type_code = b.entity_type left join amountquery c on a.id = c.id , c.rn = 1
here sqlfiddle show how works.
Comments
Post a Comment