不太明白需求,这样?
select a.username, a.posttime, max(b.reposttime),count(b.num)
from tb1 a join tb2 b on a.topic=b.topic and a.username=b.username
group by a.username, a.posttime

解决方案 »

  1.   

    就是tb1里放着发贴的标题 时间 作者...
    tb2里是标题 回帖的时间 作者...  
    要求查询每个帖子的标题 发布时间 回帖数量 最后回复的作者和时间
      

  2.   


    并没有查询max(b.reposttime)的username
      

  3.   

    求一SQL语句 
    tb1 topic username body   posttime   
    tb2 topic username rebody reposttime num字段 
    查询 topic tb1.username posttime max(reposttime) count(num)和max(reposttime)对应的tb2.username  
    求教怎么写就是tb1里放着发贴的标题 时间 作者... 
    tb2里是标题 回帖的时间 作者...   
    要求查询每个帖子的标题 发布时间 回帖数量 最后回复的作者和时间select m.* , n.* from tb1 m
    left join
    (
      select t.* from tb2 t where reposttime = (select max(reposttime) from tb2 where topic = t.topic)
    ) n
    on m.topic = n.topic
      

  4.   


    select topic,tb1.username,posttime,
    (select max(b.reposttime) from tb2 as b where a.topic=b.topic and a.username=b.username),
    (select count(c.num) from tb2 as c where a.topic=c.topic and a.username=c.username),
    (select max(d.reposttime)from tb2 as d where a.topic=d.topic and a.username=d.username),
     from tb1 as a
      

  5.   


    num列的查询的是count(num)
    要怎么写?