我的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
答案 0 :(得分:0)
你可以这样做:
;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;
请注意:尽量不要在SQL中执行这些格式化操作。 SQL 不是有关格式化的内容。