我正在使用Phalcon查询语言(PHQL)使用NOT BETWEEN进行查询,但它无法正常运行应用程序挂起。 有人可以告诉我如何做到这一点。非常感谢你。 有我的疑问。
$sql = "SELECT c.* FROM table as c
WHERE not exists c.activated NOT BETWEEN :f1: and :f2: ";
$parameters['f1'] = '2017-10-01';
$parameters['f2'] = '2017-10-05';
$result= $this->modelsManager->executeQuery($sql,
$parameters);
每次运行查询时都会离开:
警告:session_destroy():尝试在第222行的C:\ xampp \ htdocs \ myapp \ app \ plugins \ SecurityPlugin.php中销毁未初始化的会话
答案 0 :(得分:1)
在我打开这个问题之前,我从未听说过Phalcon查询语言(PHQL),但您尝试的语法在SQL中无效。试试这个:
$sql = "SELECT c.* FROM table as c WHERE NOT c.activated BETWEEN :f1: and :f2: ";
$parameters['f1'] = '2017-10-01';
$parameters['f2'] = '2017-10-05';
$result= $this->modelsManager->executeQuery($sql,
$parameters);
不( your_predicate_here )
您需要的只是NOT来反转谓词返回的true / false值。例如如果日期在日期之间(true),则将其反转为false,因此它等于“not between”。
MySQL 5.6架构设置:
CREATE TABLE Table1
(`activated` datetime)
;
INSERT INTO Table1
(`activated`)
VALUES
('2016-12-01 00:00:00'),
('2017-10-01 00:00:00'),
('2017-10-05 00:00:00')
;
查询1 :
SELECT c.*
FROM table1 as c
WHERE NOT c.activated BETWEEN '2017-10-01' AND '2017-10-05'
<强> Results 强>:
| activated |
|----------------------|
| 2016-12-01T00:00:00Z |