Re: how/what should be the query for this result

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hari,

You are so funny.

Cloud, this could be the answer you are looking for:

select
p1.P_no,
p1.b_no,
p1.status,
p1.build_date
from
Progress p1
where
build_date = (
select
max(build_date)
from
Progress p2
where
p2.P_no = p1.P_no and
p2.b_no = p1.b_no)

Or it can be:

select
p1.P_no,
p1.b_no,
p1.status,
p1.build_date
from
Progress p1
where
build_date = (
select
max(build_date)
from
Progress p2
where
p2.b_no = p1.b_no)

Or it can be

select
p1.P_no,
p1.b_no,
p1.status,
p1.build_date
from
Progress p1
inner join (
select
P_no P_no,
b_no b_no,
max(build_date) build_date
from
Progress
group by
P_no,
b_no) p2 on
p2.P_no = p1.P_no and
p2.b_no = p1.b_no and
p2.build_date = p1.build_date

Or it can be

select
p1.P_no,
p1.b_no,
p1.status,
p1.build_date
from
Progress p1
inner join (
select
b_no b_no,
max(build_date) build_date
from
Progress
group by
b_no) p2 on
p2.b_no = p1.b_no and
p2.build_date = p1.build_date





"Hari" <hkvats_1999@xxxxxxxxx> wrote in message
news:1151509079.446956.36560@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Query for getting o/p specified by you could be...

SELECT P_No, B_No, Max(Status) Status, Max(Build_Date)
FROM Progess
GROUP BY P_No, B_No
==============================================

Pls note this query is executed against the sample data specified by
you.


-Hari Sharma
NIIT Technologies, India

I have 1 table "Progress"

P_no b_no status build_date
----------------------------------------------------------------
25 1 First_slab 2006/4/5
25 1 second slab 2006/5/6
25 2 first slab 2006/1/2
25 2 third slab 2006/2/3

o/p should be as
Pno,bno, status, max(build_date)

sample o/p can be as below
25 1 second slab 2006/5/6
25 2 third slab 2006/2/3



.



Relevant Pages