表1:Projects
字段:ID,ContractMoney(合同金额)
表2:Finances
字段Porject_ID,ReceivedMoney(回款金额)
(一对多的关系)
要求:筛选出 没有全部回款的项目 和
筛选出 全部回款的项目
一共两个sql语句
2.select * from Projects p left join (select Porject_ID sum(ReceivedMoney)ReceivedMoney from Finances group by Porject_ID) f on p.ID=f.Porject_ID
where ContractMoney<=isnull(ReceivedMoney ,0)
百度搜索一下子查询,可以解决
2.select * from Projects p left join (select Porject_ID sum(ReceivedMoney)ReceivedMoney from Finances group by Porject_ID) f on p.ID=f.Porject_ID
where ContractMoney<=isnull(ReceivedMoney ,0)