我有一个带有UNPIVOT
的SELECT语句SELECT dycd_acnam, dycd_dynam, dycd_value
FROM GCATT.dbo.tblDaycode UNPIVOT (
dycd_value FOR dycd_dynam IN (
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)
) AS pvtDaycode
GROUP BY dycd_acnam, dycd_dynam, dycd_value
并返回类似
的值dycd_acnam | dycd_dynam | dycd_value
----------------------------------------
MT | Monday | 1
MT | Tuesday | 1
MT | Wednesday | 0
MT | Thursday | 0
如何在行dycd_acnam
之前添加行号?尝试了RANK()
,但它返回了错误的值。我想尽可能避免使用#Temp表。
答案 0 :(得分:3)
如果您只想在结果中添加增量列,可以添加
ROW_NUMBER() OVER (ORDER BY (SELECT 0))
到SELECT
列表