如果我尝试使用别名(scount、samount),我的 sql 查询将出现问题。该查询在没有别名的情况下运行正常,并且仅使用第一个(scount)也可以正常工作,但是一旦我添加第二个(samount),查询就无法执行。我认为这与我出于某种原因进行减号查询有关。
谁能帮我解决这个问题,以便我可以使用别名返回值。
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