简体   繁体   English

如何计算用户名下的行数?

[英]how do i count the amount of rows under a username?

I am making a forum for my school project and on my home page I want to make some kind of a leaderboard where you can see the top 10 posters + how much they have postet.我正在为我的学校项目创建一个论坛,在我的主页上,我想制作某种排行榜,您可以在其中看到前 10 名海报以及他们有多少postet。 Ill add a picture of my data base so if you maybe know how it would work please let me know.生病添加我的数据库的图片,所以如果你知道它是如何工作的,请告诉我。 Database数据库

I don't know what you mean, but if you mean the database query, it can be something like this:我不知道你的意思,但如果你的意思是数据库查询,它可以是这样的:

SELECT username, 
       COUNT(*) AS total_post 
FROM your_table 
GROUP BY username 
ORDER BY COUNT(*) DESC 
LIMIT 10

I assume your table name posts.我假设你的表名帖子。 You can replace it by your table name.您可以将其替换为您的表名。

SELECT COUNT(post) as total_post, username FROM posts GROUP BY username;

It will return something like它会返回类似的东西

total_post   username 

   5         username

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM