27,579
社区成员
发帖
与我相关
我的任务
分享
SELECT t.CP_Name as stype,h.CP_Name as sindu,sum(isnull(c.CT_ConMoney,0)) as samount,
isnull(sum(g.CG_GathingMoney),0) as spay
FROM CommonParameter t
Left join FlyPM_Contract c on c.CT_ConClassify=t.CP_ID and c.CT_ConStatus <> 'CP1108191039380001'
and c.ct_consigndate between '2001-1-1' and '2014-12-12'
LEFT JOIN CommonParameter h on c.CT_ConType = h.CP_ID
LEFT JOIN flypm_contractGathering g on c.ct_id=g.ct_id
WHERE t.CPC_ID = 'CPC110409084846000139'
group by t.CP_Name,h.CP_Name,t.CP_Index,g.CG_GathingMoney
ORDER BY t.CP_Index,t.CP_Name
用distinct去除重复
SUM 简单解决这个问题。
[quote=引用 2 楼 u011212968 的回复:] 这3条数据是同一条数据,spay是另一个表的关联过去的。
这3条数据是同一条数据,spay是另一个表的关联过去的。
SELECT t.CP_Name as stype,h.CP_Name as sindu,sum(isnull(c.CT_ConMoney,0)) as samount,
isnull(sum(g.CG_GathingMoney),0) as spay
FROM CommonParameter t
Left join FlyPM_Contract c on c.CT_ConClassify=t.CP_ID and c.CT_ConStatus <> 'CP1108191039380001'
and c.ct_consigndate between '2001-1-1' and '2014-12-12'
LEFT JOIN CommonParameter h on c.CT_ConType = h.CP_ID
LEFT JOIN flypm_contractGathering g on c.ct_id=g.ct_id
WHERE t.CPC_ID = 'CPC110409084846000139'
group by t.CP_Name,h.CP_Name,t.CP_Index
ORDER BY t.CP_Index,t.CP_Name
你没发现那3个123的spay不一样吗?这字段你不要了?