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 |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2009-05-12 : 06:50:39
|
| i have tables TABLEA (i have more columns)# ColumnA CoulmnB ColumnC ......1 1 2 P 2 1 2 O3 2 20 U4 2 5 F5 4 3 Oif Row of ColumnA And ColumnB equal so i want just the row of Columns p i mean:# ColumnA CoulmnB ColumnC ......1 1 2 P 3 2 20 U4 2 5 F5 4 3 Ohow i can do it?thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-12 : 07:07:15
|
[code]declare @TABLEA table( [#] int, ColumnA int, ColumnB int, ColumnC char(1))insert into @TABLEAselect 1, 1, 2, 'P' union allselect 2, 1, 2, 'O' union allselect 3, 2, 20, 'U' union allselect 4, 2, 5, 'F' union allselect 5, 4, 3, 'O'select [#], ColumnA, ColumnB, ColumnCfrom ( select [#], ColumnA, ColumnB, ColumnC, row_no = row_number() over (partition by ColumnA, ColumnB order by ColumnC DESC) from @TABLEA ) twhere t.row_no = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-12 : 10:02:37
|
quote: Originally posted by inbs i have tables TABLEA (i have more columns)# ColumnA CoulmnB ColumnC ......1 1 2 P 2 1 2 O3 2 20 U4 2 5 F5 4 3 Oif Row of ColumnA And ColumnB equal so i want just the row of Columns p i mean:# ColumnA CoulmnB ColumnC ......1 1 2 P 3 2 20 U4 2 5 F5 4 3 Ohow i can do it?thanks
will the columnC values be always P,U,F,O...what do you want if you've more than 1 occurance of cola,colb but with different ColC values (may be U & F) |
 |
|
|
|
|
|
|
|