mysql 联结查询语句

WBOY
Release: 2016-06-13 11:58:03
Original
927 people have browsed it

mysql 联合查询语句

本帖最后由 amu1433 于 2014-05-04 04:02:35 编辑 bbslist

id         title           userid
1          222             1
2          222             2
3          133             1
4          222             1
5          222             2
6          222             3

表user

id         name           
1          张三            
2          李四           
3          王麻子

表user的id对应表bbslist里面的userid


表bbslist放的是用户发布的帖子.
怎么按用户的发帖量排序....



           




------解决方案--------------------
$sql="select a.id, a.name , count(b.id) as num  from user a left join bbslist  b on b.userid=a.id group by b.userid order by num desc";<br />$r=mysql_query($sql);<br />while($row=mysql_fetch_assoc($r)){<br />       echo $row['name'] .'------------' . $row['num'] .'篇<br>';<br />}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template