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'
输出:
updateDate cHospital cHospital1 cHospital2
01/15/2010 1234
01/15/2010 1234
但据我所知,我的查询必须返回一个空行。
查询中的错误在哪里?
答案 0 :(得分:1)
尝试在您的cHospital条件中添加一些括号,否则您将不会达到预期目标:
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'
也:
... updateDate between '1/30/2010' and '1/28/2010' ...
^正在进行字符串比较而不是日期比较,请尝试更改为:
... updateDate between '2010-01-30' and '2010-01-28' ...
答案 1 :(得分:0)
我的问题已解决。根据jspcal的指导,我将datetype更改为datetime。
现在我得到了预期的输出。