0
如果我嘗試使用別名(scount,samount),那麼sql查詢將無法正常工作。查詢運行正常,沒有別名,它也可以很好地使用第一個(scount),但只要我添加第二個(samount)查詢無法執行。我認爲這與我由於某種原因進行減號查詢有關。在sql查詢中使用負號返回別名失敗
任何人都可以幫我解決這個問題,這樣我就可以用別名返回值。
select count(t.invoiceID) scount, sum(amount) samount -
IFNULL(
(
select sum(p.amount) as pamount
from invoice t, invoiceFactoring ift, InvoiceType it, Payment p
where t.issuerID = 38
AND ift.invoiceID = t.invoiceID
AND t.invoiceID = p.invoiceID
AND it.invoiceTypeID = t.invoiceTypeID
AND now() > date_add(t.invoiceExpiryDate, INTERVAL 45 DAY)
)
,0)
from invoice t, invoiceFactoring ift, InvoiceType it
where issuerID = 38
AND ift.invoiceID = t.invoiceID
AND it.invoiceTypeID = t.invoiceTypeID
AND now() > date_add(t.invoiceExpiryDate, INTERVAL 45 DAY)
AND t.disabled = 0
AND it.typeCategory = 1
嗯好吧有道理,不知道我明白如何使我的查詢雖然工作。也許你(或其他人)可以更具體地說明如何讓查詢返回:scount,samount。 (請:-)) –
更新了我的答案 – keymone