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
Explain the features of oracle?
Can multiple cursors being opened at the same time?
What is a data lock in oracle?
What is an oracle transaction?
Explain enable novalidate constraint.
How can you use check constraints for self referential integrity?
Is there any function in oracle similar like group_concat of mysql?
What happens if you set the sga too low in oracle?
What is execute immediate in oracle?
Which is better Oracle or MS SQL? Why?
Explain oracle data types with examples?
What are the ways tablespaces can be managed and how do they differ?
What is recovery manager in Oracle?
List the various oracle database objects?
What do you understand by a database object? Can you list a few of them?