无法在数据库中查找列和表的多个错误

时间:2015-07-07 13:09:27

标签: mysql

我上周刚刚开始使用MySQL,我试图编写代码来检查特定地址的最早计费记录实例,并将其标记为" NEW"。它还应该识别帐户是否已被取消,并将取消记录的第一个实例标记为" NEW"。代码编译,但每当我尝试通过输入地址进行测试时,我会收到"错误代码:1054。未知列' BillingRecords.Address'在' where子句'"我觉得我已经尝试过针对太阳下列引用的每个修复(有/没有反引号,单引号,数据库名称,表名等)。我应该如何引用代码中的列以避免这种情况错误?此外,由于我无法正确测试,因此代码中可能还有其他一些错误。如果你发现任何事情,我真的很感激一些反馈。

我使用的列是: 地址varchar(145)YES MUL NULL 取消varchar(45)YES NULL 日期日期YES NULL

我希望转发这个问题没问题。我还没有让代码工作。原始帖子here.

问题中的代码

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;

0 个答案:

没有答案