Q) How to Find Max Date from each Group? (Asked in Infosys
(INFI)Interview)

Answers were Sorted based on User's Feedback



Q) How to Find Max Date from each Group? (Asked in Infosys (INFI)Interview) ..

Answer / 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

Q) How to Find Max Date from each Group? (Asked in Infosys (INFI)Interview) ..

Answer / sudipta santra

select market_id, mkt_name, max(sale_dt)
from market
group by market_id, mkt_name;


Note: This is the only correct answer

Is This Answer Correct ?    5 Yes 0 No

Q) How to Find Max Date from each Group? (Asked in Infosys (INFI)Interview) ..

Answer / d ashwin

AS OUR EXAMPLE HR SCHEMA FOR GROUP WISE MAX DATE...

SELECT * FROM HR.EMPLOYEES
WHERE HIRE_DATE IN
(SELECT MAX(HIRE_DATE) FROM HR.EMPLOYEES
GROUP BY DEPARTMENT_ID);

FOR SINGLE ROW MAX DATE...
SELECT * FROM
(
SELECT * FROM HR.EMPLOYEES
ORDER BY HIRE_DATE DESC)
WHERE ROWNUM = 1;

Is This Answer Correct ?    4 Yes 2 No

Q) How to Find Max Date from each Group? (Asked in Infosys (INFI)Interview) ..

Answer / suman rana

select market_id, mkt_name, sale_dt from (
select market_id, mkt_name, sale_dt, max(sale_dt) over
(partition by market_id, mkt_name ) Max_sale_dt
from market )
where sale_dt = Max_sale_dt

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Oracle General Interview Questions

Hi all, Can any one give answer for this question. Suppose im having employee table with fields, eno, ename, dept, address1, address2, address3. In address field employee can fill only address1 or address2 or address3... at a time he can fill three address fields. now i want all employee names who filled only one address field.. Plz its urjent can any one give querry.. Thanks in advance.

4 Answers   JPMorgan Chase,


can u call user defined functions in select statements

2 Answers  


How many types of synonyms in Oracle?

0 Answers   MCN Solutions,


What is a private synonym?

0 Answers  


Explain table?

0 Answers  






Give syntax for SQL and ORACLE joins.

0 Answers   TCS,


How to restrict the duplicate records in table valuesets

2 Answers   IBM,


How to run create database statement?

0 Answers  


what is the exact diiference between DBMS and RDBMS

4 Answers   Tesco,


what is the syntax of update command?

3 Answers   Semantic Space,


Can the default values be assigned to actual parameters?

1 Answers  


how to join query for one source type is oracle another source type is sql server ?

0 Answers   iGate,


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)