我正在尝试为 mysql 编写一个查询,(Search Module)
因为要在同一个表中执行选择操作而遇到困难。
我的查询:
(SELECT * FROM user WHERE `user_name` like '%TOM%' OR `user_name` like '%AN%'
and `login_datetime` BETWEEN '2013-01-01 00:00:00' and '2013-02-31 23:59:59')
OR
(SELECT * FROM user WHERE `user_name` like '%PHP%' OR `user_name` like '%BA%'
and `login_datetime` BETWEEN '2013-02-01 00:00:00' and '2013-03-31 23:59:59')
AND
(SELECT * FROM user WHERE `user_name` like '%SUN%' OR `user_name` like '%MOON%'
and `login_datetime` BETWEEN '2013-03-01 00:00:00' and '2013-04-31 23:59:59')
NAND
(SELECT * FROM user WHERE `user_name` like '%RAJ%' OR `user_name` like '%MUTH%'
and `login_datetime` BETWEEN '2013-04-01 00:00:00' and '2013-06-31 23:59:59')
NOR
(SELECT * FROM user WHERE `user_name` like '%BAG%' OR `user_name` like '%LAP%'
and `login_datetime` BETWEEN '2013-05-01 00:00:00' and '2013-07-31 23:59:59')
上面提到的查询是我的场景。在无法更改的情况下,我正在尝试为此编写一个查询。
笔记:
- 上述查询在单个表中执行。
- OR、NAND、NOR、AND运算可以根据情况互换。
- 这取决于用户,他需要如何搜索。
我尝试了很多方法来实现逻辑,但我在各个阶段都面临问题。
检查我的尝试: MySQL IN BETWEEN with no condition Doctrine Query from Mysql Select Query with OR and NAND