SELECT
p.container_name AS containerName,
cargo_name AS cargoName,
cargo_maintain_time_now AS cargoExpireTime
FROM
t_cargo t
LEFT JOIN (
SELECT t1.id, t1.container_name AS container_name FROM t_container t1
UNION ALL
SELECT t2.id, t2.shelf_address AS container_name FROM t_shelf t2
) p ON t.location_id = p.id
LEFT JOIN t_store d ON t.location_id = d.id
WHERE
t.state = 1
and t.storehouse_num = #{storehouseNum}
<if test='timeType=="1"'>
AND (DATEDIFF(now(), cargo_maintain_time_now) >=-7 and DATEDIFF(now(), cargo_maintain_time_now) <=7 )
</if>
<if test='timeType=="2"'>
AND (DATEDIFF(now(), cargo_maintain_time_now) >=-30 and DATEDIFF(now(), cargo_maintain_time_now) <=30 )
</if>
ORDER BY cargo_maintain_time_now ASC
SELECT
p.container_name AS containerName,
cargo_name AS cargoName,
cargo_maintain_time_now AS cargoExpireTime
FROM
t_cargo t
LEFT JOIN (
SELECT t1.id, t1.container_name AS container_name FROM t_container t1
UNION ALL
SELECT t2.id, t2.shelf_address AS container_name FROM t_shelf t2
) p ON t.location_id = p.id
LEFT JOIN t_store d ON t.location_id = d.id
WHERE
t.state = 1
and t.storehouse_num =1599963047676340007
AND (DATEDIFF(now(), cargo_maintain_time_now) >=-30 and DATEDIFF(now(), cargo_maintain_time_now) <=30 )
表示
DATEDIFF函数,用啦之后 那现在的时间写前面,要判断的时间写后面,然后写一个范围就行啦