gpt4 book ai didi

mysql - 如何查找发布最多事件的人

转载 作者:行者123 更新时间:2023-11-29 06:17:44 25 4
gpt4 key购买 nike

我正在使用mysql。这是我的sql

  SELECT LIMIT 1
users.id,
COUNT(events.id) AS events_count
FROM
INNER JOIN 'events' ON users.id = events.user_id
GROUP BY
users.id
ORDER BY
COUNT(events.id) DESC

这是我收到的错误

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN 'events' ON users.id = events.user_id
GROUP BY
users.id' at line 5:
SELECT
users.id,
COUNT(events.ID) AS events_count
FROM
INNER JOIN 'events' ON users.id = events.user_id
GROUP BY
users.id
ORDER BY
COUNT(events.id) DESC

最佳答案

您似乎在 FROM 子句后缺少表名。此外,您的 LIMIT 语法也是错误的。看这里引用http://dev.mysql.com/doc/refman/5.1/en/select.html

SELECT 
users.id,
COUNT(events.id) AS events_count
FROM users
INNER JOIN events ON users.id = events.user_id
GROUP BY
users.id
ORDER BY
COUNT(events.id) DESC
LIMIT 1

关于mysql - 如何查找发布最多事件的人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5494338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com