我想对联接的表执行选择并检索那些行,其中四列中至少有一个在两个给定日期之间。
目前我有这个:
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'
无效。