select A.log_date, A.log_filtime, A.id, B.counts from log_info as A
  inner join (select match_id, count(*) as counts from opinion 
               group by match_id) as op 
  on A.id = op.match_id 
  where A.username = 'zhuxx' 
  order by A.id desc 

解决方案 »

  1.   

    select log_date,log_filtime,id from log_info 
    inner join (select match_id, count(*) as counts from opinion group by match_id) as op on log_info.id = op.match_id 
    where username = 'zhuxx' order by log_info.id desc
      

  2.   

    谢谢各位的帮助,不过问题还是没有解决,newdongkui(老乌鸦) 的最后一个解答也不是正确的,select log_date,log_filtime,id from log_info inner join select * from (select match_id, count(*) as counts from opinion group by match_id) op on log_info.id = op.match_id where log_info.username = 'zhuxx' order by log_info.id desc 
    这样可以查出一条纪录,但是不能把所有log_info表中的纪录都查出来,因为当opinion表中没有关于log_info表中的纪录时,是查不出来。难道真的只有去用数组,把log_info表中的纪录先存入数组,然后再根据具体的id来查opinion表中相匹配的记录数?
      

  3.   

    打错了,是select A.log_date, A.log_filtime, A.id, B.counts from log_info as A
      inner join (select match_id, count(*) as counts from opinion 
                   group by match_id) as op 
      on A.id = op.match_id 
      where A.username = 'zhuxx' 
      order by A.id desc 
    可以查出一条纪录,但是不能把所有log_info表中的纪录都查出来。不是我上面打的那样。
      

  4.   

    改成左连接就能把log_info中的所有记录都查出来了。select A.log_date, A.log_filtime, A.id, B.counts from log_info as A
      left join (select match_id, count(*) as counts from opinion 
                   group by match_id) as op 
      on A.id = op.match_id 
      where A.username = 'zhuxx' 
      order by A.id desc