求助如何做到这样的查询 select a.id,a.name,(select..

浏览:1891 发布日期:2015/05/16 分类:求助交流 关键字: select
求助如何做到下面这样的查询。。

table a (分类表)
id name
1 l
2 ll
3 lll

table b (内容表)
id cid xname
1 2  x
2 1  xx
3 2  xxx
4 1  xxxxx
5 1  xxxxxxx

select a.id,a.name,(select count(id) as counts from b where b.cid=a.id) from a

return :
id  name  counts
1  l     3
2  ll     2
3  lll     0
最佳答案
评论( 相关
后面还有条评论,点击查看>>