本帖最后由 abcdefg0099 于 2024-6-21 09:38 编辑
successit 发表于 2024-6-21 08:00
你这个需求,其实用活字格自带的统计字段,在页面中也可以直接实现的,视图也写了个,你可以参考下
我的是自带数据库的视图,按照你的写法不行
WITH 入库 AS
(
SELECT "采购入库主表id",SUM(金额) AS 入库金额 FROM "采购入库子表" GROUP BY "采购入库主表id"
),
付款 AS
(
SELECT "采购入库主表id",SUM(金额) AS 付款金额 FROM "采购入库付款子表" GROUP BY "采购入库主表id"
)
SELECT
T.ID AS "ID",
ISNULL(T1.入库金额,0) AS 入库金额,
ISNULL(T2.付款金额,0) AS 付款金额,
ISNULL(T1.入库金额,0) - ISNULL(T2.付款金额,0) AS 未付金额
FROM "采购入库主表" T
LEFT JOIN 入库 T1 ON T1."ID" = T.ID
LEFT JOIN 付款 T2 ON T2."ID" = T.ID
|