求一SQL语句,想了一下午了!
我有两个表如下
Q_ArticleClass表记录文章分类,字段有
id int 4(pk)
classname varchar 20 //分类名
qid int 4 //圈子ID
Q_Blog表 存放文章ID
id int 4(pk)
blogArticleId int 4 //文章ID
qid int 4 //圈子ID
classid int 4 //Q_ArticleClass表的ID
现在偶传入参数qid偶想要得到这个圈子所有分类及分类中的文章数,效果如果
日记(10)
asp.net(20)
请问这样的sql语句要怎么写.谢谢.
------解决方案--------------------select a.qid, count(b.id) from Q_ArticleClass a left join Q_Blog b on a.id = b.classid
group by a.qid
------解决方案--------------------try
-----------------------
select a.ClassName,b.文章数 from Q_ArticleClass a
inner join(
select qid,count(qid) as 文章数 from Q_Blog
group by qid ) b on a.qid=b.qid
where qid=1
------解决方案--------------------select b.classname,count(a.id) from Q_Blog a,Q_ArticleClass b where a.qid = 1 group by b.classid,b.classname
------解决方案--------------------..掉了,
select b.classname,count(a.id) from Q_Blog a,Q_ArticleClass b where a.qid = 1 and a.classid = b.id group by a.classid,b.classname