别名不在MYSQL中处理IF条件
作者:互联网
我正在编写一个mysql查询并收到错误.
“Unknown column ‘dat’ in ‘field list'”
由于在mysql的IF条件中使用别名而发生此错误.
这是mysql查询:
SELECT
nCustomerID,
dDateRegistered,
(select count(nPlayerID) from credit_logs
where nPlayerID=nCustomerID) as total_clog,
(select count(nPlayerID) FROM bl_transaction_history
where nPlayerID=nCustomerID) as total_tran,
(select count(nCustomerID) from customer_freeplays
where nCustomerID=nCustomerID) as total_free,
(select dDateAdded from bl_transaction_history
where nPlayerID=nCustomerID) as dat,
(select DATEDIFF(now(),dat)/30 ) as date_differece1,
(select DATEDIFF(now(),dDateRegistered)/30 ) as date_difference2,
IF (dat IS NOT NULL,(select DATEDIFF(now(),dat)/30 ),
(select DATEDIFF(now(),dDateRegistered)/30 )) as date_difference
FROM bl_customers
WHERE nAccountStatus=1
and bDeleted=0
having total_clog>0
or total_tran>0
or total_free>0
任何帮助都会被appriciated ..
标签:mysql-error-1064,mysql,alias 来源: https://codeday.me/bug/20190902/1789137.html