잔액 열에 where 절을 사용하여 아래 쿼리의 데이터를 필터링하는 방법. 어디 조건에서 균형을 사용할 때 [알 수없는 열 "잔액"의 "where 절"] 오류가 나타납니다. 발견 일치 지불 기록이없는 경우Where 절을 사용하여 조인 된 mysql 테이블의 데이터 필터링
select *,(it.Total - p.Amount) as Balance
from invoices i
left outer join invoice_items it
on i.ID=it.InvoiceID
left outer join payment p
on p.InvoiceID=it.InvoiceID
where Balance!=0;
또한이 대신 잔액 항목에서 null 값을 표시하는, 나는 invoice_items 테이블의 총 값이 필요합니다.
'어디에서 (it.Total - p.Amount)! = 0;'작동해야합니다 : http://stackoverflow.com/questions/200200/can-you-use-an-alias-in-the-where- 절 -In-mysql – danihp