在我的两列数据中,我只想保留ColumnTne中ColumnTwo中值最高的唯一值。
例如 ColumnOne ColumnTwo
2 6
3 2
7 8
2 7
3 4
7 3
我想要结果:
ColumnOne ColumnTwo
2 7
3 4
7 8
答案 0 :(得分:0)
您可以使用group by语句执行此操作:
select Column1, max(Column2)
from your_table
group by Column1
答案 1 :(得分:0)
delete t1
from myTable t1
left join (select t2.Column1, max(t2.Column2) maxColumn2
from myTable t2
group by t2.Column1) tMax
on t1.Column1 = tMax.Column1
and t1.Column2 = tMax.maxColumn2
where tMax.Column1 is null
答案 2 :(得分:0)
以下查询将帮助您完成具有巨大数量的表的输出。记录:
create table table1_new as (select * from table1) with no data;
insert into table1_new
select columnone, max(columntwo) over(partition by columnone) from table1 group by columnone;
验证数据然后交换表名:
drop table table1;
rename table1_new to table1;