November 4, 2009 at 3:31 am
Hi,
I have 2 records in my database Table let say
Date Status TaskName ProjectName
Today Completed ABC Test
Today-2 Pending ABC Test
Now what i need is depend upon the max date i want the record so i need only 1 row from above sample data.
Date Status TaskName ProjectName
Today Completed ABC Test
I tried
select Max(Date) from <Table Name>
Group by Status,TaskName,ProjectName
But of no use still it gives me the 2 Records.
Thanks in advance.
Parth
November 4, 2009 at 3:39 am
remove status column from your group by!
---------------------------------------------------------------------------------
November 4, 2009 at 3:56 am
then how do i have latest status..??
November 4, 2009 at 4:01 am
You have to be clear with your test data and expected result. It was very vague information that you are giving! Anyway, if you need the latest status based on the date (latest date) for each task and project from your table, then you would write something like this, (not tested as there is no test data)
Select * from (Select *, Row_number() OVER (PARTITION BY task,
Project name order by date desc) as row_no
FROM urtable) t
Where row_no = 1
---------------------------------------------------------------------------------
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply