SELECT * FROM *****
WHERE ((first_appeared_on BETWEEN DATE_SUB( '2015-07-28' , INTERVAL 1 DAY ) AND '2015-07-28')
or (last_appeared_on BETWEEN DATE_SUB( '2015-07-28' , INTERVAL 1 DAY ) AND '2015-07-28'))
在上面的查询中,我不想一次又一次地输入日期(2015-07-28)我可以使用变量并为该变量赋值吗
day ='2015-07-28';
SELECT * FROM *****
WHERE ((first_appeared_on BETWEEN DATE_SUB(day , INTERVAL 1 DAY ) AND day)
or (last_appeared_on BETWEEN DATE_SUB( day , INTERVAL 1 DAY ) AND day))
答案 0 :(得分:0)
这可以在MySQL中使用user-defined variable:
完成SET @day = '2015-07-28';
SELECT * FROM *****
WHERE ((first_appeared_on BETWEEN DATE_SUB( @day , INTERVAL 1 DAY ) AND @day)
or (last_appeared_on BETWEEN DATE_SUB( @day , INTERVAL 1 DAY ) AND @day));