是这样的    有个讨论模块  发帖主表   A  
-----------------------------  
A.id  A.文章标题  A.发帖时间  A.发帖者
回贴表     B  
-----------------------------------------  
B.id 主表ID(A.id)B.回复内容  B.回复时间 B.回复人 
现在想通过SQL语句实现这样的功能:在列表页中如何查出所有的发帖者和回复人,并统计总数? 
谢谢老大们!

解决方案 »

  1.   

    一样的表啊,要一起查吗?条件
    所有的发帖者 select disticnt A.发帖者 from A
    发帖者人数   select count(disticnt A.发帖者) from A
    回复人       select disticnt B.回复人 from B
    回复人人数   select count(disticnt B.回复人) from Bselect A.发帖者,B.回复人 from A inner join B on A.Aid = B.Aid
    select count(disticnt A.发帖者),count(disticnt B.回复人) from A inner join B on A.Aid = B.Aid
      

  2.   

    select [回复人]=count(distinct(B.回复人)),[发帖者]=count(distinct(A.发帖者 )) 
    from A join B on a.ID=b.AID
      

  3.   

    --不考虑重复
    select 发帖者 from 发帖主表
    union all
    select 回复人 from 回贴表
    union all
    select cast(count(*) as varchar) 总数 from
    (
      select 发帖者 from 发帖主表
      union all
      select 回复人 from 回贴表
    ) t
      

  4.   

    --考虑重复
    select distinct 发帖者 from 发帖主表
    union all
    select distinct 回复人 from 回贴表
    union all
    select cast(count(*) as varchar) 总数 from
    (
      select 发帖者 from 发帖主表
      union all
      select 回复人 from 回贴表
    ) t
      

  5.   

    select 发帖者 from 发帖主表 
    union all
    select 回复人 from 回贴表 select @@rowcount