我想对联接表执行select并检索那些行,其中四列中至少有一列在两个给定日期之间。
目前我有:
SELECT
t1.Id,
t1.DateCr AS t1DateCr,
t1.DateUpd AS t1DateUpd,
t2.DateCr AS t2.DateCr,
t2.DateUpd AS t2DateUpd
FROM
Table1 AS t1,
Table2 AS t2,
WHERE
t1.Id = t2.t1Id
AND (t1.DateCr BETWEEN '2018-10-29' AND '2018-11-04'
OR t1.DateUpd BETWEEN '2018-10-29' AND '2018-11-04'
OR t2.DateCr BETWEEN '2018-10-29' AND '2018-11-04'
OR t2.DateUpd BETWEEN '2018-10-29' AND '2018-11-04')
GROUP BY t1.Id
这能用更优雅的方式写吗?而不是重复 BETWEEN
好几次?
我不能用 GREATEST
以及 LEAST
,因为我不想选择日期大于或小于给定范围但不在其中的行。
以及 (t1.DateCr,t1.DateUpd,t2.DateCr,t2.DateUpd) BETWEEN '2018-10-29' AND '2018-11-04'
不起作用。
暂无答案!
目前还没有任何答案,快来回答吧!