各位大神,是这样的,表article中同一个mid会有多行数据,表member同一mid只会有一行数据。
我希望查询同一mid下表article中sum(pname)与表member中scores的差值与0的取大值(我是这么写的:max(sum(-sum(a.pname),b.scores),0)),然后再把所有mid下的前述求大值加总。
我是这么写的,好像不对。或者有什么好办法么?还是只能遍历求和?
select sum(max(sum(-sum(a.pname),b.scores),0) ) from article as a left join member as b on a.m2′
谢谢各位大神!
回复讨论(解决方案)
select sum(max(a.pname-b.scores,0) )
from
( select mid, sum(pname) as pname, sta form article where sta