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 to define default values for formal parameters?

677


Where do you use decode and case statements?

648


How to get execution statistics reports on query statements?

674


How many types of database triggers exist?

646


What are the various constraints used in oracle?

642






What are the oracle built-in data types?

645


How to initialize variables with default values?

718


How to see free space of each tablespace?

677


i wrote a pl/sql procedure. it must run every sunday 4.40 How can i schedule it with the help of dbms_jobs (or another other procedure with out creating bat file,exe file)

1879


What are the execution control statements?

708


In Oracle Applications We are Using Sub Ledger Accounting. When we Transfer the Data all modules (AP,AR,CE,FA) to SLA We done Some customizations? What are They??

1438


How to rename an index in oracle?

698


How to retrieve values from data fields in record variables?

656


What are the four Oracle system processes that must always be up and running for the database to be useable?

673


What is a partition in oracle?

635