建临时表插入一个序号字段时时÷排序问题
比如有表 table ,有A,B,C三个字段,现要order by A,B,C 来排序并且在前面加一个序号字段,建了一个临时表:
SELECT IDENTITY (int, 1, 1) AS id, A, B,C
INTO #tmp
FROM table where ***
ORDER BY A,B,C
查询 #tmp 这个表时, select * from #tmp order by id 发现并不是 按照预期的 A,B,C 来排序的,不知道问题出在哪里。
------解决方案--------------------SELECT IDENTITY (int, 1, 1) AS id, A, B,C INTO #tmp
FROM
(SELECT top 100 percent * FROM [TABLE] WHERE *** ORDER BY A,B,C)T
下边这个查询中必须top 配合order by才行