我想这件事已经太久了,弄糊涂了!我正试图在MySQL中为以下场景提供一个CakePHP查询:
每个记录都有两个日期;为了简单起见,我将它们称为F& I。它们决定数据的质量,如下所示:
前两个很简单:
红色:
$conditions['AND'] = array('F' => null, 'I' => null);
绿色:
$conditions['AND'] = array(
'F >=' => Three months ago,
'I >=' => Three months ago
)
但我对第三种选择有困难。我试过几样东西,我知道它是这样的:
$conditions['NOT'] = array(
'AND' => array(
'F >=' => Three months ago,
'I >=' => Three months ago
),
'AND' => array(
'F' => null,
'I' => null
)
)
但很明显,这是行不通的,因为它对‘和’有两个不同的值。
发布于 2014-04-28 12:32:08
我觉得你的布尔逻辑有个问题。如果您希望F&I表示过去三个月内的日期,那么您就排除了F >=三个月或I >=三个月的任何条目。
在你的布尔逻辑上使用德摩根定律就不会那么令人困惑了-- NOT (F >= three months OR I >= three months)
和F < three months AND I < three months
是一样的。因此,对于第三条规则,条件数组如下所示:
array('conditions' => array('AND' => array('F <' => three months, 'I <' => three months)));
发布于 2014-04-28 10:10:49
我不确定,但试试看:
$conditions['AND'] = array(
'NOT' => array(
'AND' => array(
'F >=' => Three months ago,
'I >=' => Three months ago
)
),
'NOT' => array(
'AND' => array(
'F' => null,
'I' => null
)
)
)
首先,否定每个条件,并且需要外部的'AND'
,因为您希望这两个条件都不是真的。
https://stackoverflow.com/questions/23347764
复制