排序问题
CREATE TABLE #table ([线长] NVARCHAR(50) ,[员工] NVARCHAR(50))
INSERT INTO #table VALUES (N’骚团长’,N’张大’)
INSERT INTO #table VALUES (N’骚团长’,N’张一’)
INSERT INTO #table VALUES (N’骚团长’,N’张二’)
INSERT INTO #table VALUES (N’骚团长’,N’张三’)
INSERT INTO #table VALUES (N’骚团长’,N’张四’)
INSERT INTO #table VALUES (N’胡泽权’,N’李大炮’)
INSERT INTO #table VALUES (N’胡泽权’,N’李一炮’)
INSERT INTO #table VALUES (N’胡泽权’,N’李二炮’)
INSERT INTO #table VALUES (N’胡泽权’,N’李三炮’)
INSERT INTO #table VALUES (N’胡泽权’,N’李四炮’)
INSERT INTO #table VALUES (N’李海平’,N’王老大’)
INSERT INTO #table VALUES (N’李海平’,N’王一’)
INSERT INTO #table VALUES (N’李海平’,N’王二’)
INSERT INTO #table VALUES (N’李海平’,N’王三’)
INSERT INTO #table VALUES (N’李海平’,N’王四’)
in (’’,’’)
SELECT
ROW_NUMBER () OVER (ORDER BY [线长] ,[员工]) AS 总编号排序,
DENSE_RANK () OVER (ORDER BY [线长] ) AS 线长_排序 ,
[线长] ,
RANK() OVER(PARTITION BY [线长] ORDER BY [员工] ) AS 员工归属线长_排序,[员工]
FROM #table (NOLOCK) WHERE [线长] IN (N’骚团长’,N’胡泽权’,N’李海平’)
ORDER BY [线长]