这句SQL怎么不对呢?请帮忙看一下. select *,case reid when id then 1 else 0 endfrom artclewhere reid=0 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from Artcle where reid = 0?select id,count(*) as recount from Artcle where id = reid group by id id,bid,sid,reid2 1 1 03 1 1 24 1 1 05 1 1 26 1 1 47 1 1 48 1 1 4这样数据多了知道了吧.执行SQL效果后应是这样:id,bid,sid,reid,recount2 1 1 0 24 1 1 0 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 select a.*,count(*) as recountfrom tablename a join tablename b on a.id=b.reidwhere a.reid=0group by a.id 用left join更好一点:select a.*,count(*) as recountfrom tablename a left join tablename b on a.id=b.reidwhere a.reid=0group by a.id 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 这个存储过程怎么写? 请教个sql语句 sql语句(续) 高手帮忙写一个SQL语句! 我要实现在一张表中有数据插入的时候,另外一张表也要有相应的数据插入!两张表没有主外键关联... 如何修改远程数据库中表的记录 性能问题:请高手为我排忧解难,在线恭候大驾光临 mysql 高分求球----我的 EXPLAIN PLAN 怎么找不出数据来呀? 100分求解,sql server compact sdf文件太大无法打开 帮忙说一下char和varchar的区别吧! sqlserver带where的查询速度变的很慢
select id,count(*) as recount from Artcle where id = reid group by id
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
from tablename a
join tablename b on a.id=b.reid
where a.reid=0
group by a.id
用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