昨天我在q查询上对戈登有一些帮助,但我在代码方面需要更多帮助
我在下面的地方有查询
SELECT message, type, count(1) as total,
STUFF( (SELECT N',' + CONVERT(NVCHAR(MAX), id)
FROM dbo.testing t2
WHERE t2.message = t.message and t2.type = t.type
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)'), 1, 1, ''
)
FROM testing t
GROUP BY message,type
HAVING count(1) > 1;
我想填充一个名为eid的字段,从1开始到我拥有的记录数,并且每个记录都有1或5或10个我们刚刚想知道的id:如果id列中有5个id,例如18,19, 20,21,22的所有这些eid将为1
喜欢此屏幕截图
我想让errorid首先从1000开始,并且每行应该递增,但是对于每行,都有以逗号分隔的相关IDS,对于该行,它们都应具有相同的errorid
答案 0 :(得分:0)
实现这一目标的一种方法是:
SELECT message
,type
,total
,ROW_NUMBER() OVER (PARTITON BY EID ORDER BY EID) AS EID
FROM (
SELECT message, type, count(1) as total,
EID = STUFF( (SELECT N',' + CONVERT(NVCHAR(MAX), id)
FROM dbo.testing t2
WHERE t2.message = t.message and t2.type = t.type
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)'), 1, 1, ''
)
FROM testing t
GROUP BY message,type
HAVING count(1) > 1
)Res1