gpt4 book ai didi

MySQLWhere子句不过滤数据

转载 作者:行者123 更新时间:2023-11-29 10:18:30 24 4
gpt4 key购买 nike

我正在尝试执行以下查询。查询正在运行,但未将数据作为 where 子句进行过滤。我无法找出问题所在

提前致谢!

 SELECT
case when count(*) = 1 then
(select chacc from xxx_1 s inner join xxx_2 d on s.MCHRRN = rrn(d)
where d.CHCHNO = dp.CHCHNO and d.CHBKBR = dp.CHBKBR AND d.CHBRCH = dp.CHBRCH AND
s.MCHPNDT = st.MCHPNDT)
else 1 end as is_multiple,
count(*) as ch_tot,
dp.CHBRCH,
dp.CHCHNO,
dp.CHBKBR,
SUM(dp.CHCHAM) as chq_amt_tot,
st.MCHPNDT,
dp.CHCHST
FROM xxx_3 st
INNER JOIN xxx_4 dp
ON st.MCHRRN = RRN(dp)
WHERE st.MCHSTAT='P' AND st.MCHAPP IN (40,50) OR (st.MCHAPP = 26 AND st.MCHSVST = 1) AND
dp.CHDWAC=29 AND dp.CHCHNO=5261 AND st.MCHPNDT BETWEEN 2018001 AND 2018100
GROUP BY dp.CHBRCH,dp.CHCHNO,dp.CHBKBR,dp.CHCHST,st.MCHPNDT
ORDER BY st.MCHPNDT ASC

最佳答案

我怀疑你只需要括号:

WHERE ( (st.MCHSTAT = 'P' AND st.MCHAPP IN (40, 50) ) OR
(st.MCHAPP = 26 AND st.MCHSVST = 1)
) AND
dp.CHDWAC = 29 AND
dp.CHCHNO = 5261 AND
st.MCHPNDT BETWEEN 2018001 AND 2018100

如果您在 bool 表达式中同时使用 ANDOR,我建议您始终使用括号。

关于MySQLWhere子句不过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49752250/

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