Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What are the differences between lov and list item?

1022


State the difference along with examples between Oracle 9i, Oracle 10g and Oracle 11i.

1004


How to fetch the row which has the max value for a column?

971


When system tablespace is created?

994


How to create id with auto_increment on oracle?

956


What are the different types of modules in oracle forms?

970


How to drop an existing view in oracle?

919


What is the dynamic sql in oracle?

1033


Explain the features of oracle?

1003


What spfile/init.ora file parameter exists to force the CBO to make the execution path of a given statement use an index, even if the index scan may appear to be calculated as more costly?

2019


What do you mean by merge in oracle and how can we merge two tables?

1020


How to define an anonymous procedure without variables?

1060


How to load data through external tables?

1098


Is oracle a relational database?

892


What do you know about normalization? Explain in detail?

912