表1 user
uid   uname  password email表2 post(留言表)
pid  uid(用户id) post_title post_content 两个表大致这样,如何取按留言数从多到少的前10名用户的uname ?

解决方案 »

  1.   

    select A.uname,count(*) as num
    from user A,post B
    where A.uid = B.uid
    group by B.uid
    order by num desc
    limit 10;
      

  2.   

    结果中 每一条num 都是1,何解?
      

  3.   

    结果中 每一条num 都是1,何解?
    不好意思,解决了,谢谢斑竹
      

  4.   

    select *
    from user
    order by (select count(*) from post where uid=user.uid) desc limit 10
      

  5.   

    select * from user
    order by (select count(*) from post
    where uid=user.uid) desc limit 10;