我有一个数据库结构,我正在尝试选择相应员工和客户、商店等的所有发票。还想对每张发票的价值求和并将其呈现为总计
我做了这个查询:
SELECT TOP 10
i.invoiceID,
s.storeName,
c.clientName,
sum(id.quantity * p.unitPrice) as total,
(e.firstName + ' ' + e.lastName) as EmpName,
i.invoiceDate
FROM
tbProduct p,
tbInvoice i,
tbInvoiceData id,
tbEmployee e,
tbStore s,
tbClient c
WHERE
i.invoiceID = id.invoiceID
AND
e.employeeID = i.employeeID
AND
s.storeID = e.storeID
AND
c.clientID = i.clientID
GROUP BY
i.invoiceID,
s.storeName,
c.clientName,
e.firstName,
e.lastName,
i.invoiceDate
order by
i.invoiceID
但 TOTAL 中的值似乎不正确(总和部分),我做错了什么......??因为如果我运行这个查询:
select top 10
a.invoiceid, sum(a.quantity * b.unitprice) as total
from
tbInvoiceData a,
tbProduct b
where
a.productID = b.productID
group by
a.invoiceid
我从发票中得到正确的值.. :(