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
What is the data pump import utility?
What is data type in oracle?
Is it possible to insert comments into sql statements return in the data model editor ?
What is recovery manager in Oracle?
hi friends i completed b.com 2004.i have 3y accounting exp. in manufacturing company.now i have completed oracle finance.pls suggest me how will get job in oracle.can i get job in oracle.
List out the difference between commit, rollback, and savepoint?
master table and child table performances and comparisons in Oracle ?
How can Oracle users be audited?
How to check the server version in oracle?
what is the use of triggers in Java program? I mean where do we use triggers in Java programming?
If any one has information regarding interview of NIC (National Informatics Centre),it would be of great help...
How to use like conditions in oracle?
How to count duplicated values in a column in oracle?
What are the original export and import utilities?
Explain the types of exception?