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)
 First Value in each group

Author  Topic 

voyager838
Yak Posting Veteran

90 Posts

Posted - 2011-02-16 : 05:02:19
Hi

I have follow table:


LogTime | A | B
2001-01-01 00:00:00 | 2 | 5
2001-01-01 00:00:00 | 1 | 7
2001-01-01 00:00:00 | 3 | 2
2001-01-01 00:10:00 | 6 | 5
2001-01-01 00:10:00 | 3 | 4
2001-01-01 00:10:00 | 2 | 9

And i want follow results:


LogTime | A | B
2001-01-01 00:00:00 | 2 | 5
2001-01-01 00:10:00 | 6 | 5


I have tried
select [LogTime] , min([A]), min([B])
from T
group by [LogTime]

But it gives me wrong results

I would appreciate someones could help me out, on this


Thx!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-02-16 : 05:08:05
SELECT LogTime, A, B
FROM (
SELECT LogTime, A, B, ROW_NUMBER() OVER (PARTITION BY LogTime ORDER BY {Insert your sequencing column name here}) AS SeqID
FROM dbo.T
) AS d
WHERE SeqID = 1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

voyager838
Yak Posting Veteran

90 Posts

Posted - 2011-02-16 : 05:56:11
Thanks Peso

That solve the problem
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-16 : 09:44:47
More methods
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/select-data-from-top-n-columns.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

voyager838
Yak Posting Veteran

90 Posts

Posted - 2011-02-18 : 17:25:34
Thank you Madhivanan.
Go to Top of Page
   

- Advertisement -