MySQL select查询返回不相关的输出

MySQL select查询返回不相关的输出,mysql,Mysql,输出: SELECT updateDate, id,cSsn,cLname,cFname,cDOB,cDOD,cCity,cState,cHospital,cCurstatus,cMmrcashworker,cTelephone FROM med_patient WHERE cCurstatus!='completed' AND cMmrcashworker = '2' AND cHospital = '1234' OR cHospital1 = '1234' OR cHospital2 ='1

输出:

SELECT updateDate, id,cSsn,cLname,cFname,cDOB,cDOD,cCity,cState,cHospital,cCurstatus,cMmrcashworker,cTelephone FROM med_patient WHERE cCurstatus!='completed' AND cMmrcashworker = '2' AND cHospital = '1234' OR cHospital1 = '1234' OR cHospital2 ='1234' AND updateDate between '1/30/2010' and '1/28/2010' order by id desc'
但据我所知,我的查询必须返回一个空行


查询中的错误在哪里?

尝试在选择条件中添加一些括号,否则or将不是您所期望的:

updateDate   cHospital   cHospital1     cHospital2

01/15/2010   1234

01/15/2010   1234
此外:

^如果要进行字符串比较而不是日期比较,请尝试更改为:

... updateDate between '1/30/2010' and '1/28/2010' ...

我的问题解决了。根据jspcal的指导,我将日期类型更改为datetime


现在我得到了预期的输出。

在我的数据库表中,我保持着2010年1月30日的状态,是否必须更改格式。。我的问题还有其他解决方案吗..您的db的值类似于'01/15/2010',因此您需要基于mm/dd/yyyy进行比较,这可以作为字符串或日期从med_patient中选择updateDate、cHospital、cHospital1、cHospital2,其中cCurstatus!='根据您的指南,我已将日期格式更改为2010-01-28,我有一个患者条目,其中一个患者更新日期为2010-01-17,但我上面的查询返回的是空行,为什么?我想传达一件事,根据我的数据库设计,我的updateDate数据类型是varchar,检查其他值是否匹配。。。如果您要更改列类型,最好将其设置为datetime(同样,“2010-01-1”看起来像输入错误,应该是“2010-01-01”)
... updateDate between '2010-01-30' and '2010-01-28' ...
... updateDate between '2010-01-30' and '2010-01-28' ...