选择 id 不同的所有行

Selecting all rows in which id is distinct

你好,我需要一些关于如何在 selecting 中 phone 数字作为 "distinction" 的度量的所有行上执行 select 语句的一些建议。

我所拥有的示例。

|ID |Name |Phone Number| Address  |
|   |     |            |          |
|1  |John | 1234567    | A.Road 1 |
|1  |John | 1234567    | B.Road 2 |
|2  |Jane | 7654321    | C.Road 3 |
|3  |Jim  | 7654321    | C.road 3 |

我想要的示例:

|ID |Name |Phone Number| Address  |
|   |     |            |          |
|1  |John | 1234567    | A.Road 1 |
|2  |Jane | 7654321    | C.Road 3 |

关于 SQL 选择对结果中的哪一行进行图片并不重要,重要的是整行可用并且它使 select 离子不同 phone 数字。希望你明白我想在这里做什么。

ANSISQL支持row_number()函数,典型的解决方案:

select t.*
from (select t.*,
             row_number() over (partition by phone_number order by id) as seqnum
      from t
     ) t
where seqnum = 1;