标题: 查询语句的修改?大家帮忙 [打印本页] 作者: yu88 时间: 2007-4-20 04:14 标题: 查询语句的修改?大家帮忙 报关表有两个字段(报关金额)和(押汇结余额)要汇总,并减去收汇表中的字段(结汇金额)汇总额,两者的差额为未收汇金额
SELECT 报关表.票号, AA.报关金额量, AA.押汇额, AA.结汇金额量, AA.报关金额量-AA.押汇额-AA.结汇金额量 AS 未收汇金额
FROM 报关表 LEFT JOIN [SELECT A.票号, A.报关金额量,A.押汇额, B.结汇金额量
FROM (select 票号,SUM(报关金额) AS 报关金额量,SUM(押汇结余额) AS 押汇额 FROM 报关表 group by 票号) A INNER JOIN (SELECT 票号,SUM(结汇金额) AS 结汇金额量 FROM 收汇表 group by 票号) B ON A.票号=B.票号]. AS AA ON 报关表.票号=AA.票号;