我对子查询/连接相当新,但我需要对从另一个查询生成的表表运行查询。我知道之前可能已经提出这个问题了,但是我找不到一个适合我的答案。
有关我的查询的基本信息:
查询1:
SELECT ipAddress,userId FROM loginAttempts WHERE browser = 'IE' GROUP BY userId
查询2:
SELECT COUNT(ipAddress) AS rows,ipAddress FROM loginAttempts GROUP BY ipAddress ORDER BY ipAddress;
主要是我需要预先形成搜索,以便仅显示达到特定条件的唯一值,然后显示从中返回的每个唯一值的数量。
这是我的查询的简化版本,但loginAttempts表跟踪每个用户的每次登录尝试,我需要查看每个用户从每个IP地址进行的登录尝试次数。例如......
user1, 5 attempts from x.x.x.4
user1, 2 attempts from x.x.x.5
user2, 10 attempts from x.x.x.4
user2, 2 attempts from x.x.x.6
etc...
提前感谢您的帮助!
答案 0 :(得分:1)
试试这个:
按用户ID分组,ipAddress
SELECT COUNT(ipAddress) AS rows,ipAddress, userId
FROM loginAttempts
GROUP BY ipAddress, userId
ORDER BY ipAddress
一起分组。我希望这会对你有所帮助