如何找出哪个用户输入了最多的文章,然后计算用户使用PHP&的MySQL。
这是我的MySQL表格。
CREATE TABLE users_articles (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
title TEXT NOT NULL,
acontent LONGTEXT NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE users (
user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(255) DEFAULT NULL,
pass CHAR(40) NOT NULL,
PRIMARY KEY (user_id)
);
答案 0 :(得分:3)
select count(*) as coun, user_id from users_articles group by user_id order by coun desc LIMIT 1
答案 1 :(得分:0)
SELECT user_id, COUNT(id) AS articles
FROM users_articles
GROUP BY user_id
ORDER BY articles DESC
LIMIT 1;