求统计sql语句
求统计sql语句,要求如下
Table catagory
catagoryid name
1 name1
2 name2
3 name3
Tbale detail
id catagoryid name
1 1 a1
2 1 a2
3 2 a3
查询每个分类的记录条数
结果如下
catagoryid name count
1 name1 2
2 name2 1
3 name3 0
------解决方案--------------------select b.catagoryid,b.name,(select count(*) from detail a where a.catagoryid = b.catagoryid) as count
from catagory b