我正在尝试从下面的查询中包含的不同表中获取列值,但是当我在where子句中检查不同条件时会给出错误。
sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_PostCode";
sql += "," + "members.member_Reference, members.member_Dob, members.member_IsBiometric, mshiptypes.mshipType_Name, mshipstatustypes.mshipStatusType_Name";
sql += "," + "membertomships.memberToMship_EndDate";
sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
sql += " "+"LEFT JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id";
sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
sql += " " + "WHERE memberToMship_PayMethod='Cash' AND mshipStausType_Name ='Live' AND mshipStatusType_Name = 'Defaulter' AND mshipStatusType_Name='Frozen'";
但它给这样的错误
Error Code: 1054
Unknown column 'mshipStausType_Name' in 'where clause'
有人可以帮我这个问题吗,我正在使用mysql ...
这是修改后的查询,但它不提取蚂蚁数据,而是给出空列值
sql = @"SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_PostCode";
sql += "," + "members.member_Reference, members.member_Dob, members.member_IsBiometric, mshiptypes.mshipType_Name, mshipstatustypes.mshipStatusType_Name";
sql += "," + "membertomships.memberToMship_EndDate";
sql += " "+"FROM members LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id";
sql += " "+"LEFT JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id";
sql += " "+"LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id";
sql += " "+"LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id";
sql += " " + "WHERE membertomships.memberToMship_PayMethod='Cash' AND mshipstatustypes.mshipStatusType_Name='Live' AND mshipstatustypes.mshipStatusType_Name = 'Defaulter' AND mshipstatustypes.mshipStatusType_Name='Frozen'"
最佳答案
如果该列的拼写是正确的,那么我认为编译器没有识别出该列属于哪个表,因为该列出现在多个表中,因此请尝试在像这样的列之前使用表名
mshiptypes.mshipType_Name
使用OR时,mshipStatusType_Name中不可能存在两个值
而不是像这样:
mshipStatusType_Name='value1' or mshipStatusType_Name='value2' ....
关于mysql - 检查where子句中出现错误的不同条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6580163/