SELECT (
SELECT count(*) as dd
FROM [121_PinYinIndex ] as a where a.[id]<b.[id]) AS bb, b.[id]
FROM [121_PinYinIndex ] AS b;
经常碰到的按成绩排名的问题也可以用同样的方法解决:
SELECT (
SELECT count(*)+1 as dd
FROM [成绩表] as a where a.[实际成绩]>b.[实际成绩]) AS bb, b.[实际成绩]
FROM [成绩表] AS b order by b.[实际成绩] desc