我在这里有这个长的 sql 查询..
SELECT c.clientid, c.clientname, c.billingdate,
case when (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) < 0 and i.date < '2012-01-01' then (select ii.total from invoice ii where ii.client = c.clientid order by ii.invoiceid desc limit 1) else (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) end as remaining,
case c.isactive+0
when '1' then 'Stop'
else 'Start'
end as Active
FROM client c
ORDER BY clientname
我收到此查询的错误,其中一行i.date < '2012-01-01'
说这i.date
是字段列表中的未知列...我该如何解决这个问题?
谢谢,J