select *,case reid when id then 1 else 0 end
from artcle
where reid=0

解决方案 »

  1.   

    select * from Artcle where reid = 0?
    select id,count(*) as recount from Artcle where id = reid group by id
      

  2.   

    id,bid,sid,reid
    2  1    1   0
    3  1    1   2
    4  1    1   0
    5  1    1   2
    6  1    1   4
    7  1    1   4
    8  1    1   4
    这样数据多了知道了吧.
    执行SQL效果后应是这样:
    id,bid,sid,reid,recount
    2  1    1   0    2
    4  1    1   0    3
      

  3.   

    select b.*,(select count(*) from bbs_Artcle a where a.reid<>0 and a.reid=b.id) as recount from bbs_Artcle b where b.bid=1 and b.sid=1 and b.reid=0
      

  4.   

    select a.*,count(*) as recount
    from tablename a
         join tablename b on a.id=b.reid
    where a.reid=0
    group by a.id
      

  5.   


    用left join更好一点:select a.*,count(*) as recount
    from tablename a
         left join tablename b on a.id=b.reid
    where a.reid=0
    group by a.id
      

  6.   

    select b.*,(select count(*) from bbs_Artcle a where a.reid<>0 and a.reid=b.id) as recount from bbs_Artcle b where b.bid=1 and b.sid=1 and b.reid=0