col3を使用してcol3の結び目を破ることを任意に選択しました。 partition
のorder by
部分をニーズに合わせて調整することができます。
/* Set up test data */
declare @test table (
col1 char(1),
col2 char(1),
col3 char(1),
col4 char(1)
)
insert into @test
(col1, col2, col3, col4)
select 'A','B','C','D' union all
select 'E','F','G','H' union all
select 'I','J','C','L' union all
select 'M','N','Z','H'
/* Here's the query */
;with cteRowNumber as (
select col1, col2, col3, col4,
row_number() over (partition by col3 order by col1) as RowNumber
from @test
)
select col1, col2, col3, col4
from cteRowNumber
where RowNumber = 1
戻り
col1 col2 col3 col4
----------------------------
A B C D
E F G H
M N Z H
あなたのクエリおよび/またはテーブル定義を投稿することができますか? –
あなたの例では、行1と3は3番目に値Cを持ちます。カラム。あなたの最終的な結果にどの列(1または3)を持ちたいのですが、それはなぜですか? –
私はこれらの行のどれが必要か気にしません。それらのいずれか。 – truthseeker