【发布时间】:2023-03-27 13:05:02
【问题描述】:
我有一个表,其中包含 id、name、dateofentry、dateofexit 和信息如下:
1, Test1, 2021-03-01, 0000-00-00
2, Test2, 2021-03-02, 2021-03-03
3, Test 3, 2021-03-03, 0000-00-00
4, Test 4, 2021-03-04, 0000-00-00
5, Test 5, 2021-03-04, 0000-00-00
现在,如果选择查询并且我想知道有多少仍然处于活动状态,因为 dateofexit 是 0000-00-00,答案应该是 4 作为 2021-03-03 留下的 ID 2 的记录。
所以我的查询是
SELECT *
FROM `table`
WHERE `dateofentry`<='2021-03-04'
AND `dateofexit`<='2021-03-04'
AND dateofexit='0000-00-00'
它将返回以下内容:
1, Test1, 2021-03-01, 0000-00-00
3, Test 3, 2021-03-03, 0000-00-00
4, Test 4, 2021-03-04, 0000-00-00
5, Test 5, 2021-03-04, 0000-00-00
这很好,但如果我执行选择查询并将日期更改为 2021-03-02,如下所示
SELECT *
FROM `table`
WHERE `dateofentry`<='2021-03-02'
AND `dateofexit`<='2021-03-02'
AND dateofexit='0000-00-00'
它只返回
1, Test1, 2021-03-01, 0000-00-00
但我希望它返回以下内容:
1, Test1, 2021-03-01, 0000-00-00
2, Test2, 2021-03-02, 2021-03-03
请帮忙,简而言之,我不想计算或显示在给定日期之前退出系统的那个
【问题讨论】:
-
'AND releaseate='releaseate?
-
releasedate 实际上是 dateofexit 而不是 releaseate
-
请编辑您的问题,不要在 cmets 中更正。
-
AND
dateofexit -
SELECT * FROM
tableWHEREdateofentrydateofexit