Sql 如何用多选键选择键表中的值

Sql 如何用多选键选择键表中的值,sql,postgresql,Sql,Postgresql,我有一个表a,数据类型如下 col1 | col2 -------- e1 | A e2 | A e3 | B e4 | B . . 基本上在col1中,id指向2个相同的值。我想要一张没有col2复制品的桌子。比如: col1 | col2 -------- e1| A e3| B e5| C . . 有没有办法在postgresql中实现这一点?我尝试使用distinct关键字,但它们共享相同的id…您可以在以

我有一个表a,数据类型如下

col1 | col2
--------
e1   | A
e2   | A
e3   | B
e4   | B
 .
 .
基本上在col1中,id指向2个相同的值。我想要一张没有col2复制品的桌子。比如:

 col1 | col2
    --------
    e1| A 
    e3| B
    e5| C 
     .
     .
有没有办法在postgresql中实现这一点?我尝试使用distinct关键字,但它们共享相同的id…

您可以在以下位置使用distinct:

这将选择行中的所有列

如果要删除行,则可以使用:

delete from t
    where t.col1 < (select max(t2.col1) from t t2 where t2.col2 = t.col1);
您可以在以下位置使用distinct:

这将选择行中的所有列

如果要删除行,则可以使用:

delete from t
    where t.col1 < (select max(t2.col1) from t t2 where t2.col2 = t.col1);
您可以按如下方式使用group by和min:

Select min(col1) as col1,
       Col2
  From t
 Group by col2;
您可以按如下方式使用group by和min:

Select min(col1) as col1,
       Col2
  From t
 Group by col2;

看起来更像是一群人!看一看MIN或MAXLooks更像一组人!看看最小值或最大值