【发布时间】:2014-11-04 06:32:26
【问题描述】:
我又遇到了另一个问题。我知道有很多与此问题相关的链接,但无法为我的查询找到确切的解决方案。这是我的查询:-
SELECT c.cust_id, c.cust_name, c.cust_mob, sum(CASE WHEN trans_type = 'Purchase' THEN total_amt ELSE 0 END) as purchase, sum(CASE WHEN trans_type = 'Sale' THEN total_amt ELSE 0 END) as sale, sum(ifnull(a.payment_amt,0)) as tot_pay, (purchase-(sale+sum(a.payment_amt))) as tot_torcv, ((sale+sum(a.payment_amt))-purchase) as tot_topay FROM bil_customers c
inner join bil_vendor_account a on(c.cust_id=a.vendor_id)
WHERE c.cust_catagory = '3'
group by cust_id
having ifnull(tot_torcv,0) between '0' and '100000'
order by a.sl_no
我不知道查询有什么问题,因为它抛出以下错误:-
1054 - “字段列表”中的未知列“购买”
请帮我解决问题。提前致谢!!
【问题讨论】:
-
你不能这样使用别名。
标签: mysql