我正在尝试将这些表合并在一起,并将星号放在任何COLOR
和WORK
旁边,这些副本只是同一个人的重复实例。
TABLE1
:
NAME COLOR WORK
----------------------------
Jane purple eDisco
Gianne Red Fashion
Daya pink Education
Sheryl pink eDisco
Jannelle green Fasion
TABLE2
:
NAME COLOR WORK
----------------------------------
Jane gray Technology
Gianne Orange Sales
Daya Purple Education
Sheryl pink FM
Jannelle pink Fashion
SQL:
SELECT *
INTO TEMP_MERGEALL
FROM TABLE1
UNION ALL
SELECT * TABLE2
ORDER BY NAME
GO
;WITH CTE as
(
SELECT
ROW_NUMBER() OVER(PARTITION BY COLOR ORDER BY COLOR) AS rno,
COLOR
FROM TEMP_MERGEALL
)
UPDATE CTE
SET COLOR = COLOR +' ***** '
WHERE rno = 2
GO
;WITH CTE as
(
SELECT
ROW_NUMBER() OVER(PARTITION BY Work ORDER BY Work) AS rno,
Work
FROM TEMP_MERGEALL
)
UPDATE CTE
SET WORK = WORK +' ***** '
WHERE rno = 2
GO
我得到了这个(它只识别COLOR和WORK的重复实例,而不是名称)
Daya pink Education
Daya purple Education *****
Gianne red Fashion
Gianne orange Sales
Jane purple ***** eDisco
Jane gray Technology
Jannelle green Fashion *****
Janelle pink ***** Fashion
Sheryl pink FM
Sheryl pink eDisco
但是,我希望得到我的结果(当有重复的名称重复时,在COLOR
和WORK
旁边添加星号)
Daya pink Education
Daya purple Education *****
Gianne red Fashion
Gianne orange Sales
Jane purple eDisco
Jane gray Technology
Janelle green Fashion
Janelle pink Fashion *****
Sheryl pink FM
Sheryl pink ***** eDisco
有什么想法?我不知道我在哪里添加GROUP BY Name
以使脚本正常工作。