0

我有一张如下表:

FA_Name| SP_Name | ALIAS_Name
------------------------------
FA1    |   SP1    | a1
FA1    |   SP1    | a2
FA1    |   SP2    | a3
FA1    |   SP2    | a4
FA1    |   SP3    | a5
FA1    |   SP3    | a6

我只想检索给定 FA_Name 的每个不同“SP_Name”的第一个 ALIAS_Name 记录。这意味着,我必须按如下方式获取记录:

FA1 |   SP1   | a1
FA1 |   SP2   | a3
FA1 |   SP3   | a5

请帮我写同样的 SQL 查询。谢谢。

4

1 回答 1

0

我得到了同样的答案,如下:

WITH duplicate AS 
(
SELECT fu_area, sp_name, analysis_name, ROW_NUMBER() OVER(PARTITION BY fu_area, sp_name 
ORDER BY fu_area, sp_name, analysis_name) AS _dupe_num 
FROM temp_rrr_test_111 WHERE 1=1
)
select * FROM duplicate WHERE _dupe_num = 1
于 2013-11-04T05:37:01.270 回答