Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
t1id amount flag1 20 11 20 11 21 02 10 02 11 03 5 13 6 1t1 is oderd by id and amountI want id amount flag1 20 12 10 03 5 1......id will be unique amount is the smalleat among same id. it is possible two records are the same.Thank.
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2008-03-25 : 13:56:48
[code]Select id, min(amount) amount, min(flag) flagfrom tablegroup by idorder by 1,2[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-03-25 : 14:22:24
use row_number() function
SELECT t.id, t.amount, t.flagFROM(SELECT ROW_NUMBER() OVER(PARTITION BY id ORDER BY amount) AS RowNo,id,amount,flagFROM t1)tWHERE t.RowNo=1