--(1)2021年至今天为止签订的合同(不含付款合同)里面,一共有多少个客户(相同的客户要合并算作一个);1171
--(2)2021年至今天为止签订的合同(不含付款合同)里面,帮我统计一个清单,就是累计合同签订额最高的15个客户。
--1,合同金额不为0
select (select objname from customer where id=info.extrefobjfield0) extrefobjfield0,SUM(info.cmoney) from (
select c.id,c.objname,isnull(c.cmoney,0) as cmoney,c.extrefobjfield0 from contract c where c.isdelete=0 and
c.categoryids in('40288041128c2bf201128c2ec8f60005','f94975f1fb07115c00fb0facd4ef12c3') and c.extrefobjfield0 in(select id from customer where categoryids='40288041128c2bf201128c2f737a000b' )
and c.signingdate>='2021-01-01' and c.cmoney<>0
union all
--2,合同金额=0
select id,objname,( select isnull(SUM(field003),0) from ufb2l7q61080374753094 where field009=c.id and requestid in(select id from workflowbase where isdelete=0))as cmoney,c.extrefobjfield0
from contract c where c.isdelete=0 and
c.categoryids in('40288041128c2bf201128c2ec8f60005','f94975f1fb07115c00fb0facd4ef12c3')
and c.signingdate>='2021-01-01' and isnull(c.cmoney,0)=0 and c.extrefobjfield0 in(select id from customer where categoryids='40288041128c2bf201128c2f737a000b' )
) info group by info.extrefobjfield0 order by SUM(info.cmoney) desc