select a.Name, count(1) as 产品数 from ProductSort a left join Product b on a.ID=b.Class group by a.Name
select a.分类 , count(*) from ProductSort a,Product b where a.分类 = b.分类 group by a.分类
两个表.一个产品分类表ProductSort 一个产品表Product ------------------ select a.分类名,count(*) from productsort a left join product b on a.分类id=b.分类id group by 分类名
Use library create proc dbo.proc1 As select 分类名,count(产品数) as 该分类产品数 from productSort as p1 left join Product as p2 where p1.分类名 = p2.分类名 group by 分类名 GOexec proc1
a.Name,
count(1) as 产品数
from
ProductSort a
left join
Product b on a.ID=b.Class
group by a.Name
where a.分类 = b.分类
group by a.分类
一个产品表Product
------------------
select a.分类名,count(*) from productsort a left join product b
on a.分类id=b.分类id group by 分类名
create proc dbo.proc1
As
select 分类名,count(产品数) as 该分类产品数 from productSort as p1 left join Product as p2
where p1.分类名 = p2.分类名
group by 分类名
GOexec proc1