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 2005 Forums
 Transact-SQL (2005)
 Select only one value (if exists)

Author  Topic 

_polarix_
Starting Member

5 Posts

Posted - 2009-07-15 : 11:56:25
Hi All.

I have a table:

A(Date) B(Time) C(Value)
2008-11-01 06.00 5.0
2008-11-01 18.00 3.0
2008-11-02 06.00 6.0
2008-11-02 18.00 9.0
2008-11-03 06.00 7.0
2008-11-03 18.00 0.0
2008-11-04 06.00 7.0
2008-11-04 18.00 0.0


As you can see I do not have the "18.00 o'clock value" for the "2008-11-03".

I need to select only 18.00 values, and if i do not have it, i have to get the "06.00 value".
So the result should be:

A(Date) B(Time) C(Value)
2008-11-01 18.00 3.0
2008-11-02 18.00 9.0
2008-11-03 06.00 0.0
2008-11-04 18.00 0.0

I think it's not too difficult, but I'm not able !!!
Thank you.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-15 : 12:48:43
[code]
SELECT A,B,C
FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY A ORDER BY B DESC) AS Seq,*
FROM Table
)t
WHERE Seq=1
[/code]
Go to Top of Page
   

- Advertisement -