作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 cakephp 做这样的查询:
WHERE text LIKE '%keyword%'
AND
(
(text LIKE '%something%')
OR (text LIKE '%something%')
OR (...)
)
AND
(
(text LIKE '%other%')
OR (text LIKE '%other%')
OR (...)
)
NOT
(
(text LIKE '%dont include%')
OR (text LIKE '%dont include%')
OR (...)
)
$conditions = array
(
'Tweet.text LIKE' => '%keyword%',
'AND' => array(
array(
'OR' => array(
// topic
array('Tweet.text LIKE' => '%something%'),
array('Tweet.text LIKE' => '%something%')
)
),
array(
'OR' => array(
// sentiment
array('Tweet.text LIKE' => '%other%'),
array('Tweet.text LIKE' => '%other%')
)
)
),
'NOT' => array(
array('Tweet.text LIKE' => '%dont include%'),
array('Tweet.text LIKE' => '%dont include%')
)
);
array(
'Tweet.text LIKE' => '%keyword%',
'OR' => array(
(int) 0 => array(
'Tweet.text LIKE' => '%other%'
),
(int) 1 => array(
'Tweet.text LIKE' => '%other%'
)
),
'NOT' => array(
(int) 0 => array(
'Tweet.text LIKE' => '%dont include%'
),
(int) 1 => array(
'Tweet.text LIKE' => '%dont include%'
)
)
)
最佳答案
请尝试以下操作:
$conditions = array(
'Tweet.text LIKE' => '%aa%', //implied and
array( //implied and
'or' => array(
array('Tweet.text LIKE' => '%11%'),
array('Tweet.text LIKE' => '%22%'),
array('Tweet.text LIKE' => '%33%'),
...
)
),
array( //implied and
'or' => array(
array('Tweet.text LIKE' => '%123%'),
array('Tweet.text LIKE' => '%456%'),
array('Tweet.text LIKE' => '%789%'),
...
)
)
'not' => array(
'or' => array(
array('Tweet.text LIKE' => '%x%'),
array('Tweet.text LIKE' => '%y%'),
array('Tweet.text LIKE' => '%z%'),
...
)
)
)
text LIKE aa
AND ( either 11, 22, 33 )
AND (either 123, 456, 789)
BUT NOT (x || y || z)`
or
、
and
或
not
的数组都是
and
。无需手动指定。
关于sql - cakephp 复杂查询多个 'OR' 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13890704/
我是一名优秀的程序员,十分优秀!