Error 1054: Unknown Column in Where Clause

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

I just started working with MySQL last week, and I'm attempting to write a code to check for the earliest instance of a billing record for a certain address and mark it as "NEW". It should also identify if an account has since been cancelled and mark the first instance of a cancelled record as "NEW". The code compiles, but whenever I try to test it by inputting an address, I receive "Error Code: 1054. Unknown column 'BillingRecords.Address' in 'where clause'" I feel like I've tried every fix for the column references under the sun (with/without backticks, single quotes, database names, table names, etc.) How exactly should I be referencing the columns in the code to avoid this error? Also, since I haven't been able to test it properly, there may be a few other errors in the code. If you notice anything, I'd really appreciate some feedback.

Code in question

SELECT Min(`Date`) INTO earliestDate FROM Billing.BillingRecords WHERE `Address` = addressToCheck; #Determines the earliest date of all instances of the specified address SELECT Min(`Date`) INTO earliestCancelDate FROM Billing.BillingRecords WHERE `Address` = addressToCheck AND `Cancel` = "Cancelled"; #Determines the earliest date of all instances of the specified address where the account has been marked as "Cancelled"  CASE     WHEN `BillingRecords`.`Address` = addressToCheck AND `BillingRecords`.`Date` = earliestDate THEN         SET isItNew = "NEW"; #Returns "NEW" if the address matches the specified address and the date matches the earliest date     WHEN `BillingRecords`.`Address` = addressToCheck AND `BillingRecords`.`Date` != earliestDate THEN         SET isItNew = "OLD"; #Returns "OLD" if the address matches the specified address and the date does not match the earliest date     ELSE         SET isItNew = NULL; END CASE;   CASE         WHEN `BillingRecords`.`Address` = addressToCheck AND `BillingRecords`.`Date` = earliestCancelDate AND `BillingRecords`.`Cancel` = "Cancelled" THEN         SET isItNewCancel = "NEW"; #Returns "NEW" if the address matches the specified address, the account is marked as "Cancelled", and the date matches the earliest cancel date     WHEN `BillingRecords`.`Address` = addressToCheck AND `BillingRecords`.`Date` != earliestCancelDate AND `BillingRecords`.`Cancel` = "Cancelled" THEN         SET isItNewCancel = "OLD"; #Returns "OLD" if the address matches the specified address, the account is marked as "Cancelled", and the date does not match the earliest date     ELSE         SET isItNewCancel = NULL; END CASE; 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!