3

我的数据库中有一些文章

+------+--------------+----------+--------+
| id   | article_name | age_from | age_to |
+------+--------------+----------+--------+
| 1337 | article 1    | 30       | 60     |
+------+--------------+----------+--------+
| 1338 | article 2    | 16       | 35     |
+------+--------------+----------+--------+
| 1338 | article 3    | 26       | 28     |
+------+--------------+----------+--------+

用户可以在前端设置一些过滤器。他可以搜索为 19 至 22 岁的人制作的文章。还有两个输入字段(年龄从和年龄到)。数据库应该返回这个:

+------+--------------+----------+--------+
| id   | article_name | age_from | age_to |
+------+--------------+----------+--------+
| 1338 | article 2    | 16       | 35     |
+------+--------------+----------+--------+

我怎么做?我不能这样做WHERE age_from >= 19 AND age_to <= 22

问候

4

1 回答 1

6

翻转逻辑:

WHERE age_from <= 22
AND   age_to   >= 19

我最喜欢对此类问题的解释,由Rudy Limeback(又名 r937)提供:http ://www.dbforums.com/6318776-post14.html

于 2013-08-13T13:22:53.150 回答