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 is the relation of a user account and a schema?

1074


You have found corruption in a tablespace that contains static tables that are part of a database that is in NOARCHIVE log mode. How would you restore the tablespace without losing new data in the other tablespaces?

1878


What is a nested table and how is it different from a normal table?

1002


What do you mean by merge in oracle?

949


What is Library Cache in Oracle?

1094


How to rename a column in an existing table?

989


Is there a combination of "like" and "in" in sql?

1023


what is the use of system.effective.date variable in oracle?

1070


how to handle exceptions in post production

1375


How to select some columns from a table in oracle?

1023


How to Truncate Table in Oracle

1115


How to initialize variables with default values?

1184


Please explain drop constraint oracle?

1050


Explain oracle data types with examples?

976


How many file formats are supported to export data?

1159