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)
 order question

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-12 : 10:51:18
table t1
group order c1 c2 c3

a 8 -----
a 6
a 4
a 4
a 4
a 7
b 1
b 7
b 2
c -----

expected result
a 4 ---
a 4
b 1 ---
b 2

I want to choose the a row in each group with
minimum two order,
how can I do that?
Thanks

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-12 : 11:00:25
What is in the 3rd column? What is the actual data and structure of the table?

What would prevent the 3rd A 4 record from coming in?

Easy to sort out, but best to post some actual data and exact expected results.




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-12 : 13:21:23
[code]
SELECT d.[Group], d.[Order], d.c1, d.c2, d.c3
FROM (
SELECT [Group], [Order], c1, c2, c3,
ROW_NUMBER() OVER (PARTITION BY [Group] ORDER BY [Order]) AS RecID
FROM t1
) AS d
WHERE d.RecID <= 2[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-12 : 13:28:49
THX!
Go to Top of Page
   

- Advertisement -