我有这个查询如下:
AS
BEGIN
SET NOCOUNT ON;
BEGIN
SELECT *
FROM (SELECT [id],
[account],
[tag],
[location],
[whoAdded],
ROW_NUMBER() OVER (PARTITION BY whoAdded ORDER BY id DESC) AS rn
FROM accountLogAccounts) AS a
WHERE rn = 1
FOR XML PATH ('users'), TYPE, ELEMENTS, ROOT ('root');
END
END
我试图在此处包括用户帐户总数以及所有标签的计数。
该表如下所示:
id, account, tag, whoAdded
1, 123, dog, bob
2, 123, cat, jon
3, 125, pig, bob
预期结果:
用户 Bob 有 2 个不同的帐户和 2 个标签
用户 jon 有 1 个不同的帐户和 1 个标签