#1054 - “字段列表"中的未知列 [英] #1054 - Unknown column in 'field list'

查看:117
本文介绍了#1054 - “字段列表"中的未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我又遇到了另一个问题.我知道有很多与此问题相关的链接,但无法为我的查询找到确切的解决方案.这是我的查询:-

SELECT c.cust_id, c.cust_name, c.cust_mob, sum(CASE WHEN trans_type = 'Purchase' THEN total_amt ELSE 0 END) 作为购买, sum(CASE WHEN trans_type = 'Sale' THEN total_amt ELSE 0END) 作为销售, sum(ifnull(a.payment_amt,0)) 作为 tot_pay, (purchase-(sale+sum(a.payment_amt))) 作为 tot_torcv, ((sale+sum(a.payment_amt))-purchase)作为 tot_topay FROM bil_customers c内连接 bil_vendor_account a on(c.cust_id=a.vendor_id)哪里 c.cust_catagory = '3'按 cust_id 分组ifnull(tot_torcv,0) 在 '0' 和 '100000' 之间由 a.sl_no 订购

我不知道查询有什么问题,因为它抛出以下错误:-

<块引用>

1054 - 'field list' 中的未知列 'purchase'

请帮我解决问题.提前致谢!!

解决方案

您的错误是,您将购买用作列,即使它是别名,您也可以使用它来代替

未测试

SELECT c.cust_id, c.cust_name, c.cust_mob, @purchase :=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) 作为销售,sum(ifnull(a.payment_amt,0)) 作为tot_pay,(@purchase-(sale+sum(a.payment_amt))) 作为tot_torcv,((sale+sum(a.payment_amt)))-@purchase) 作为 tot_topay FROM bil_customers c内连接 bil_vendor_account a on(c.cust_id=a.vendor_id)哪里 c.cust_catagory = '3'按 cust_id 分组ifnull(tot_torcv,0) 在 '0' 和 '100000' 之间由 a.sl_no 订购

如果我错过了什么,请告诉我

I am back with another problem. I know there are many links related to this issue but unable to find the exact solution for my query. Here is my query :-

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

I dont know what is wrong with the query as it is throwing the following error:-

1054 - Unknown column 'purchase' in 'field list'

Please help me sorting out the problem. Thanks in advance!!

解决方案

Your error is, you are using the purchase as column even though it is alias you can use this instead

Not tested

SELECT c.cust_id, c.cust_name, c.cust_mob, @purchase :=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

just let me know if i miss something

这篇关于#1054 - “字段列表"中的未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆