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.
| Author |
Topic |
|
kjk_kjp
Starting Member
18 Posts |
Posted - 2011-02-28 : 10:37:26
|
| Morning,I have a query that returns the following data: ID SEC R_COST C_COST1 ab 60 2752 ab 60 2753 ab 60 2752 xy 45 2754 xy 45 2755 xy 45 275What I need the query to return is the following:ID SEC R_COST C_COST1 ab 60 2752 ab 60 03 ab 60 02 xy 45 2754 xy 45 05 xy 45 0Basically I'm only wanting to see/calc the C_COST once per SEC.Any thoughts?Thanks! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-02-28 : 10:42:51
|
you can make use of row_number() over (partition by SEC order by ID) in your query. Return C_COST value when row_number() returns 1 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
kjk_kjp
Starting Member
18 Posts |
Posted - 2011-02-28 : 10:44:10
|
| Good Idea, I will play round with the RowNumber and see if I can get it to work for my needs.Thanks for the idea. |
 |
|
|
kjk_kjp
Starting Member
18 Posts |
Posted - 2011-02-28 : 10:56:14
|
| The RowNumber worked - thanks again! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-02-28 : 11:08:29
|
you are welcome KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|