日期:2014-05-18  浏览次数:20377 次

不显示删除回复显示所有回复显示星级回复显示得分回复 两表查询,查询公司的时候,顺便把该公司的产品数量统计出来
不显示删除回复显示所有回复显示星级回复显示得分回复 两表查询,查询公司的时候,顺便把该公司的产品数量列出来

产品的数量没有在表里存放,是需要统计的,麻烦各位了

公司表 compay

ID gsmc
1 A
2 B
3 C
4 D

产品表 gongying
ID companyID
1 2
2 2
3 4
4 1

查询公司得到表
ID gsmc gsum
1 A 1
2 B 2
3 C 0
4 D 1


------解决方案--------------------
SQL code
select
  row_number(order by getdate()) as id,
  a.id,
  isnull(count(b.companyID),0) as gsum
from
   compay a left join ongying b
on
  a.id=b.companyID
group by
  a.id