在条件client != id
select *,str_to_date(invoice_date,'%d/%m/%Y') as date,invoice_to as id,
(select mob_no from client_info where mob_no = id ) as client
from client_invoice
where client != id
having str_to_date(invoice_date,'%d/%m/%Y') >= '$fdate'
and str_to_date(invoice_date,'%d/%m/%Y') <= '$tdate'
ORDER BY date DESC
请帮助解决此问题。在此先感谢。
答案 0 :(得分:2)
您无法在WHERE
子句中引用别名,您必须使用HAVING
。
SELECT *, str_to_date(invoice_date, '%d/%m/%Y') AS date,
invoice_to AS id,
(SELECT mob_no FROM client_info WHERE mob_no = invoice_to) AS client
FROM client_invoice
WHERE STR_TO_DATE(invoice_date, '%d/%m/%Y') BETWEEN '$fdate' AND '$tdate'
HAVING client != id