我的SQL查询结果
EmployeeID EmployeeName Department 1 John Sales 2 Robert Sales 3 Sudhir Sales 4 Roj Development
输出应为
EmployeeID EmployeeName Department 1 John Sales 2 Robert 3 Sudhir 4 Roj Development
你可以这样做:
;WITH CTE AS ( SELECT EmployeeID, EmployeeName, Department, ROW_NUMBER() OVER(PARTITION BY Department ORDER BY(SELECT 1)) rownum FROM table1 ) SELECT EmployeeId, EmployeeName, CASE rownum WHEN 1 THEN Department ELSE '' END AS Department FROM CTE ORDER BY EmployeeID;