0
SELECT
   doctors. fullname,
   dutyroster.date,
   dutyroster.time
FROM
   dutyroster
INNER JOIN doctors ON doctors.docid = dutyroster.docid
WHERE doctors.docid = $doc_id AND
dutyroster.date = DATE(NOW()) AND DATE(NOW())+ INTERVAL 1 DAY
ORDER BY dutyroster.`date`  ASC";

此查询用于从名为 dutyroster 的表中查找特定医生信息。我只想获取当天和明天的文档信息。但这不起作用。

我做了第二个,它也不起作用,因为它返回当前一个和所有下一个日期

SELECT
    doctors. fullname,
    dutyroster.date,
    dutyroster.time
FROM
    dutyroster
INNER JOIN doctors ON doctors.docid = dutyroster.docid
WHERE doctors.docid = $doc_id AND
DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= dutyroster.date
ORDER BY dutyroster.`date`  ASC"
4

2 回答 2

1

代替

... AND dutyroster.date = DATE(NOW()) AND DATE(NOW())+ INTERVAL 1 DAY

尝试

... AND (dutyroster.date = CURDATE() OR 
         dutyroster.date = CURDATE() + INTERVAL 1 DAY))

或更简洁的方式,正如@MarcM 建议的那样

... AND dutyroster.date IN (CURDATE(), CURDATE() + INTERVAL 1 day)
于 2013-03-06T22:14:03.437 回答
0

从您的第一次尝试开始,您几乎看起来像是在尝试编写 COBOL!此外,为了将来参考,“这不起作用”不是一个有用的评论。你应该说出实际发生的事情。

无论如何,尝试将您的 where 子句更改为:

WHERE doctors.docid = $doc_id AND (dutyroster.date = CURRENT_DATE OR dutyroster.date = CURRENT_DATE + INTERVAL 1 DAY)

或者:

WHERE Doctors.docid = $doc_id AND dutyroster.date IN (CURRENT_DATE, CURRENT_DATE + INTERVAL 1 DAY))

于 2013-03-06T22:27:06.330 回答