mysql if没用_别名不在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 .. ?

提前致谢.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值