简体   繁体   English

MYSQL:错误1054-未知列

[英]MYSQL: Error 1054 - Unknown Column

Before we start, I apologize for my MYSQL novice status. 在开始之前,我对MYSQL新手身份表示歉意。 I'm trying to self-teach and struggling a bit with basic the basic structure. 我正在尝试自学,并在基本的基本结构上稍作挣扎。

Background on my question: Consider a company that issues bills once a quarter... and roughly two months after the end of the last quarter. 我的问题的背景:考虑一家公司每季度发行一次账单,而在上一季度末之后大约两个月。 I have a table (Quarter_Identify) that has several columns: 我有一个表(Quarter_Identify),其中有几列:

  • Quarter_Start EX: 01-01-2010 Quarter_Start EX:2010年1月1日
  • Quarter_End EX: 03-31-2010 Quarter_End EX:2010年3月31日
  • Quarter_Ident EX: 1000 <--- iterating number for each quarter (next quarter will be 1001) Quarter_Ident EX:每个季度1000 <---迭代次数(下一个季度为1001)
  • Date_Billed This is the field I'm trying to populate from another table Date_Billed这是我要从另一个表填充的字段

The other table (Billing_List_1) contains: 另一个表(Billing_List_1)包含:

  • Date_Billed EX: 05-23-2010 Date_Billed EX:05-23-2010
  • Lots of other nonsense related to the customers 许多其他与客户有关的废话

We take all the orders during the quarter, and bill about 60 days after it ends. 我们将在该季度接受所有订单,并在结束后约60天付款。 So, in the example above, the 5-23-2010 billing would be related to the Jan - Mar quarter (we bill really late). 因此,在上面的示例中,2010年5月23日的帐单与1月至3月的季度有关(我们开帐真晚)。 I would like to take this date and populate it back as the Date_Billed associated with Quart_Ident "1000". 我想获取此日期并将其填充为与Quart_Ident“ 1000”关联的Date_Billed。

I'm fairly close and from my research I think I'm running into the issue that my "Where" clause includes a reference to the as-yet not created table "Skyline". 我已经很接近了,从我的研究中我认为我遇到了一个问题,即我的“哪里”子句包含对尚未创建的表“天际线”的引用。 The "skyline" table gets everything together, but is essentially off by a month (I gave up trying to figure out the DateDiff function). “天际线”表将所有内容组合在一起,但实际上相差一个月(我放弃尝试找出DateDiff函数)。 So, I use the bottom piece to offset the result by one and get the right answer... except that it tells me I have an unknown column in my where clause (error 1054) the issue. 因此,我用最下面的那一部分将结果偏移一个,并得到正确的答案……除了它告诉我在我的where子句(错误1054)中有一个未知列之外。

Select * from
    (select Billing_List_1.date_billed, quarter_identify.quarter_start,
      quarter_identify.quarter_end, quarter_identify.quarter_ident from Billing_List_1
    join quarter_identify
    on Billing_List_1.date_billed > quarter_identify.quarter_start 
      and Billing_list_1.date_billed < quarter_identify.quarter_end)
as SKYLINETABLE;

update quarter_identify A
    set A.date_Billed = SKYLINETABLE.date_Billed 
    where A.quarter_ident = SKYLINETABLE.quarter_ident - 1

Any thoughts would be much appreciated. 任何想法将不胜感激。 Have a great evening all. 祝大家晚上愉快。


Solution per TEEZ: Thanks again for the great help. 每个TEEZ的解决方案:再次感谢您的大力帮助。

update quarter_identify A Left join 
    (Select * from
        (select     Billing_List_1.date_billed, 
                    quarter_identify.quarter_start, 
                    quarter_identify.quarter_end, 
                    quarter_identify.quarter_ident from billing_list_1
        join quarter_identify
        on Billing_list_1.date_billed > quarter_identify.quarter_start 
        and Billing_list_1.date_billed < quarter_identify.quarter_end) 
    as T)
    as SKYLINETABLE on 1
    set A.date_billed = SKYLINETABLE.date_billed 
    where A.quarter_ident = SKYLINETABLE.quarter_ident - 1

I think you are wrong. 我认为你错了。 what is SKYLINE table in update query? 更新查询中的SKYLINE表是什么?

You are joining tables in update query but table is not specified. 您正在更新查询中联接表,但未指定表。 you should use your first query in join with update query. 您应该将第一个查询与更新查询结合使用。

you need to use join SKYLINETABLE in join with your update query. 您需要在更新查询中使用join SKYLINETABLE。

Like below: 如下所示:

update quarter_identify A left join (Select * from
    (select Billing_List_1.date_billed, quarter_identify.quarter_start,
      quarter_identify.quarter_end, quarter_identify.quarter_ident from Billing_List_1
    join quarter_identify
    on Billing_List_1.date_billed > quarter_identify.quarter_start 
      and Billing_list_1.date_billed < quarter_identify.quarter_end)) as SKYLINETABLE on[... specify on condition....]
    set A.date_Billed = SKYLINETABLE.date_Billed 
    where A.quarter_ident = SKYLINETABLE.quarter_ident - 1

Please do required changes 请进行必要的更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM