我正在托管一个用户获取SQL日志的平台,我想为它做一些高分,所以有十分之一的用户获得最多的日志。
所有注册用户都会在日志中获得自己的ID' ID' ID'显示为:' id'。所以在用户ID'是在大写字母和日志'它没有首都。 我希望有这样的查询:
SELECT username,ID FROM users ORDER BY COUNT (id) FROM logs LIMIT 10;
但这不起作用,所以也许你们有人有解决方案?
答案 0 :(得分:0)
简单SELECT U.username,U.ID
FROM users U
INNER JOIN logs L
on U.id = L.id
Group by U.username,U.ID
ORDER BY COUNT (id) FROM LIMIT 10
应该有效
SELECT users.username, users.id
FROM users
LEFT JOIN logs on users.id = logs.id
GROUP BY users.id
ORDER BY COUNT (logs.id)
LIMIT 10;
答案 1 :(得分:0)
试试这个,您需要加入表格并使用群组功能,这对您尝试实现的目标非常有用:
SELECT users.username as u, users.id as i
FROM users
LEFT JOIN logs on users.id = logs.id
GROUP BY i
ORDER BY COUNT (logs.id)
LIMIT 10;
或尝试使用别名:
SELECT users.username, users.id, COUNT(logs.id) as quantity
FROM users
LEFT JOIN logs on users.id = logs.id
GROUP BY users.id
ORDER BY COUNT(logs.id)
LIMIT 10;
尝试此操作以实现日志计数:
document.getElementById("theDivs")
答案 2 :(得分:0)
{{1}}