SELECT Row_number()
OVER (
ORDER BY setsid) AS Set_No,
setsid,
testid
FROM examsets
WHERE testid = 4
结果是: -
Set_No
-------------------
1
2
3
4
5
6
7
我想要结果为: -
Set_No
-------------------
a
b
c
d
e
f
g
我该怎么做?
答案 0 :(得分:1)
你可以用它。它不会处理返回超过26行的情况。
char(96+row_number() over(order by setsid))
从AA
转到ZZ
将为您提供676个不同的值。
select char(((T.N / 26) % 26) + 65) + char((T.N % 26) + 65) as Set_No
from (
select row_number() over(order by setsid) - 1 as N
from YourTable
) as T
答案 1 :(得分:0)
SELECT
char(ascii(row_number() over (order by setsid))+48) as Set_No
setsid,
testid
FROM
examsets
WHERE
testid = 4