我正在使用的查询有多个名字,一个电子邮件地址的姓氏。我如何只选择第一行并忽略剩余。 像
Tracy Dugan td@test.com
stephen stacy td@test.com
Ron Thomas td@test.com
结果Tracy Dugan td@test.com 我有多行具有相同的电子邮件地址。如何实现
SELECT distinct f.email_address,TITLE,FIRST_NAME,LAST_NAME FROM
#tempFinal F,temp htc
where f.EMAIL_ADDRESS = htc.EMAIL_ADDRESS
答案 0 :(得分:1)
按email_address
对结果集进行分区,并使用row_number
分配序列,然后过滤。使用order by
子句
select firstname, lastname, email_address from (
select firstname, lastname, email_address, row_number() over
(partition by email_address order by firstname, lastname) as ranker
from table ) Z where ranker = 1