首页 新闻 搜索 专区 学院

关于两个表sql语句的问题

0
悬赏园豆:20 [已解决问题] 解决于 2018-11-07 16:15

表1:Projects
字段:ID,ContractMoney(合同金额)

表2:Finances
字段Porject_ID,ReceivedMoney(回款金额)

(一对多的关系)

要求:筛选出 没有全部回款的项目 和
筛选出 全部回款的项目

一共两个sql语句

Melody.Gkx的主页 Melody.Gkx | 初学一级 | 园豆:196
提问于:2018-11-06 14:58
< >
分享
最佳答案
1
  1. 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)

收获园豆:20
fangq | 菜鸟二级 |园豆:417 | 2018-11-06 15:28
其他回答(2)
0

百度搜索一下子查询,可以解决

会长 | 园豆:9577 (大侠五级) | 2018-11-06 15:06
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)

xxy12 | 园豆:124 (初学一级) | 2018-11-06 15:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册