编写一个查询,该查询返回具有InvoiceDate的发票 2016年4月1日之前,且余额应高于 所有未付发票的平均余额。的 查询结果应显示InvoiceNumber,InvoiceDate, 每个此类发票的发票总额和余额。分类 查询结果按Balancedue降序排列。 (注意:应付余额= InvoiceTotal – PaymentTotal -CreditTotal 未付发票是余额为<> 0)* /
的发票 PaymentTotal
- CreditTotal AS BalanceDue
FROM Invoices
WHERE InvoiceDate < 2016-04-01 AND InvoiceTotal - PaymentTotal
- CreditTotal >
(SELECT InvoiceTotal - PaymentTotal
- CreditTotal AS BalanceDue
FROM Invoices
HAVING AVG(InvoiceTotal - PaymentTotal
- CreditTotal) <> 0)
我已经尝试了上述方法,但似乎无法正确解决问题。