我想要一个在数据库中搜索多个相同条目的mysql查询。
例如:
**Username Access_point Mac_address Authdate**
ALAIN AP01 00:00:00:00:00 2013-11-22 05:00:01
ALAIN AP01 00:00:00:00:00 2013-11-22 04:59:10
ALAIN AP02 00:00:00:00:00 2013-11-22 04:59:01
ALAIN AP01 00:00:00:00:00 2013-11-22 04:58:50
ALAIN AP03 00:00:00:00:00 2013-11-22 04:57:55
ALAIN AP01 00:00:00:00:00 2013-11-22 04:50:01
ALAIN AP02 00:00:00:00:00 2013-11-22 03:00:01
我想要一个查询,列出同一行(Authdate除外),并在用户名上输入Group By,以查看上次在AP01上连接ALAIN的次数。
我不知道你是否清楚???
我曾经这样试过:
SELECT COUNT(username), username, (access_point), access-point, (mac_address), mac_address
FROM table
HAVING COUNT(username) > 1
AND COUNT(access_point)> 1
AND COUNT(mac_address) > 1
GROUP BY username
感谢您的帮助。
答案 0 :(得分:0)
我不知道你的桌子叫什么 - 在你的例子中它叫做“桌子”,但我猜你把它粘贴到SO中就改了。
如果要计算过去一小时内所有接入点上所有用户的连接数,可以使用此查询:
SELECT
COUNT(*) AS NumberOfConnections, Username, Access_Point
FROM
table
WHERE
Authdate > DATE_SUB(Authdate, INTERVAL 1 HOUR)
GROUP BY
Username, Access_Point;
如果您只需要AP01上ALAIN的数据,那就是:
SELECT
COUNT(*) AS NumberOfConnections, Username, Access_Point
FROM
table
WHERE
Authdate > DATE_SUB(Authdate, INTERVAL 1 HOUR)
AND
Username = 'ALAIN'
AND
Access_Point = 'AP01'
GROUP BY
Username, Access_Point;