gpt4 book ai didi

php - 选择 cl.t_sc_1=1 OR cl.t_sc_2=1 OR cl.t_sc_3=1 AND column1=10

转载 作者:太空宇宙 更新时间:2023-11-03 11:39:41 25 4
gpt4 key购买 nike

我有一个问题

SELECT DISTINCT SQL_CALC_FOUND_ROWS cl.id AS id,
cl.column1 AS column1,
cl.column2 AS column2,
cl.column3 AS column3,
cl.t_sc_1 AS t_sc_1,
cl.t_sc_2 AS t_sc_2,
cl.t_sc_3 AS t_sc_3
FROM classifieds AS cl
WHERE (cl.t_sc_1 = 1 OR cl.t_sc_2 = 1 OR cl.t_sc_3 = 1)
AND column1 = 10 AND column2=10 AND column3=10
ORDER BY cl.id ASC

我想得到结果是否(t_sc_1 =1 OR t_sc_2 =1 OR t_sc_3=1)OR the_three_columns=1 AND column1=10 等,...我得到的结果是 t_sc_1 =1 和 t_sc_2=1 并且t_sc_3 =1 和 column1=10 等等。因此,只有 t_sc_1 =1 的行或只有 column3 =1 的行不会显示在结果中。

真正的查询是动态的,有时“或”部分包括两个 cl.t_sc_1=1(如 (cl.t_sc_1=1 OR cl.t_sc_2=1))有时包括示例中的三个。

我知道子句是否不存在,但有没有办法实现这一点?

感谢帮助

最佳答案

我们打电话

column1 = 1   as  a
column2 = 1 as b
column3 = 1 as c
column4 = 10 as d

你说你想要的是:

(a + b + c) + (a.b.c.d)
= a + b + c + a.b.c.d

其中,使用 bool 代数,等价于:

a + b + c.(1 + a.b.d)
= a + b + c.1
= a + b + c

意思是:

where (
column1 = 1
or column2 = 1
or column3 = 1
)
or (
column1 = 1
and column2 = 1
and column3 = 1
and column4 = 10
)

相当于:

where column1 = 1
or column2 = 1
or column3 = 1

或者:

where 1 in (column1, column2, column3);

关于php - 选择 cl.t_sc_1=1 OR cl.t_sc_2=1 OR cl.t_sc_3=1 AND column1=10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43038722/

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