gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:05:54 26 4
gpt4 key购买 nike

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

但实际上据我所知,我的查询必须返回一个空行。

查询错误在哪里?

最佳答案

尝试在您的 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' ...

关于MySQL select 查询返回不相关的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2080282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com