怎么取合计值?
有两张表,如下
TableA
auto_id ,prod_childid,……
1 , 1 ,
2 , 2 ,
TableB
auto_id , prod_childid,prod_number
是空表
需要的效果
prod_id , Sum(prod_number)
1 , 0
2 , 0
想要实现这样的效果,怎么做?
------解决方案--------------------select *,prod_number=(select sum(prod_number) from B where prod_childid=A.prod_childid) from A
------解决方案--------------------select prod_childid as prod_id ,isnull(sum(prod_number),0) from TableA a left join
TableB b on a.prod_childid=b.prod_childid group by prod_id