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


Please Help Members By Posting Answers For Below Questions

How do I uninstall oracle 11g?

561


Can a formula column be obtained through a select statement ?

1845


What is ASM (Automatic Storage Management) in Oracle?

712


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.

2886


if you ctreate table identity

1847






How to bring a tablespace online?

518


How can I convert single byte kana characters into multi byte kana characters and vice-versa.

1933


Is a rollback possible to any savepoint?

556


What is a Garbage Collection? and what is full recursive Garbage collection?

2389


What are the oracle differences between nvl and coalesce

516


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?

1806


How to execute a stored procedure in oracle?

618


In SAP ECC 6.0 , under DB02 tcode , Tablespace name to be explain stepy step all the col

3700


How to turn on or off recycle bin for the instance?

611


Explain do view contain data?

583