Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Last record with zero value

Author  Topic 

imrul
Starting Member

36 Posts

Posted - 2011-04-05 : 00:48:52
I want to retrive the last wage with 0 value

Table:

id wage date
-----------------------------------
1 15 01.01.2011
1 0 08.01.2011
1 0 15.01.2011
1 23 22.01.2011
2 0 01.01.2011
2 0 08.01.2011
2 12 22.01.2011

My output will be like

id wage date
-----------------------------------
1 0 15.01.2011
2 0 22.01.2011

Can anyone help?

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2011-04-05 : 01:10:17
hi,

your output is somehow not related to your data in your table; or am I reading this wrong? hence it's hard to understand how you get this.
in your output how do you differ between those two records?

anyways, try something like:

select
id
,wage
,max(date)
from Table_wage
where
wage = 0
group by id, wage
Go to Top of Page

imrul
Starting Member

36 Posts

Posted - 2011-04-05 : 06:16:16
Thanks Slimt
Go to Top of Page
   

- Advertisement -