我有 3 个表,A, B
并且C
, 有列
UserId, CompanyId, Quantity, Rate
我想做查询返回如下查询的结果
SELECT
(A.Quantity + B.Quantity + C.Quantity) AS TotalQuantity,
SUM(A.Quantity * A.Rate) + SUM(C.Quantity * C.Rate) AS TotalAmount,
TotalQuantity/TotalAmount AS Result
FROM
A, B, C
WHERE
(A.UserId = 1 AND A.CompanyId = 1)
AND
(A.UserId = B.UserId AND A.UserId = C.UserId AND A.CompanyId = B.CompanyId
AND A.CompanyId = C.CpmpanyId)
我试图运行这个查询,但它没有按预期的方式工作。我在这里遗漏了一些东西。请帮助我。
Table A
UID CID Quantity Rate
1 1 90 60
1 1 100 9
Table B
UID CID Quantity
1 1 100
1 1 50
Table C
UID CID Quantity Rate
1 1 5 5
1 1 5 5