我的查询如下:
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个标签
答案 0 :(得分:0)
Select count(distinct whoAdded), count(distinct tag), whoadded
FROM accountLogAccounts
group by whoadded
应该返回
2, 2, bob
1, 1, jon
如果您需要实际文本,请相应地应用字符串连接。