开发者

MySQL counting question

开发者 https://www.devze.com 2023-01-01 01:35 出处:网络
How do 开发者_Python百科I find out which user entered the most articles and then count how many articles that user entered using PHP & MySQL.

How do 开发者_Python百科I find out which user entered the most articles and then count how many articles that user entered using PHP & MySQL.

Here is my MySQL tables.

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)
);


select count(*) as coun, user_id from users_articles group by user_id order by coun desc LIMIT 1


SELECT user_id, COUNT(id) AS articles 
FROM users_articles 
GROUP BY user_id 
ORDER BY articles DESC
LIMIT 1;
0

精彩评论

暂无评论...
验证码 换一张
取 消