Q) How to Find Max Date from each Group? (Asked in Infosys
(INFI)Interview)
Answer Posted / niladri chatterjee
SQL> Select * From Market;
MARKET_ID MKT_NAME AREA SALE_DT
---------------------- -------- ---- ----------
1 uss NE 25-JAN-12
1 uss NE 24-FEB-12
1 uss NE 20-JUN-11
1 uss NE 15-MAR-11
2 rus SE 21-MAR-11
2 rus NE 24-APR-11
3 ger SE 20-FEB-11
3 ger NE 22-MAR-11
3 ger NE 24-FEB-12
My Answers:-
For the Single Max Row:
Select * From (Select * From market Order By Sale_Dt Desc)
Where rownum = 1;
Followings are for each Groups:
Select *
from market a
where a.sale_dt =
(select max(b.sale_dt) from market b
where a.market_id = b.market_id);
OR
select market_id, mkt_name, max(sale_dt)
from market
group by market_id, mkt_name;
Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
How do I uninstall oracle 11g?
Can a formula column be obtained through a select statement ?
What is ASM (Automatic Storage Management) in Oracle?
I have some query regarding Report generation from Oracle Apps "PO module". I have to generate a report where table columns are as below: Vendor_name Invoice No PO Number Item_Quantity Value of Goods Date of Shipping Name_of_the_transport Date_of_receipt_issued. Now my questions is :from which table/column I can get the information of "Name_of_the_transport" column. Thanks in advance.
if you ctreate table identity
How to bring a tablespace online?
How can I convert single byte kana characters into multi byte kana characters and vice-versa.
Is a rollback possible to any savepoint?
What is a Garbage Collection? and what is full recursive Garbage collection?
What are the oracle differences between nvl and coalesce
How many objectname will be created for a single table drop function? Why 'flashback' query giving error "ORA-38312: original name is used by an existing object" while getting the table?
How to execute a stored procedure in oracle?
In SAP ECC 6.0 , under DB02 tcode , Tablespace name to be explain stepy step all the col
How to turn on or off recycle bin for the instance?
Explain do view contain data?