设定固定时间段:8.2---》8.5
也就是:两个时间段,只要有交集就能筛选出来:
下面的两个sql语句,实现的效果是一样的:
1:$sql="select * from fs_ads where `start_time` <= ‘$ed‘ and `end_time` >= ‘$sd‘";
2:
$sql="select * from (
select ads_id,file_id,client_type,client_name,brand,model,cal_type start_time,end_time,
CASE
when (start_time>=‘$sd‘) then start_time
when (start_time<‘$sd‘) then ‘$sd‘
end as start1,
CASE
when (end_time>=‘$ed‘) then ‘$ed‘
when (end_time<‘$ed‘) then end_time
end as end1
from fs_ads )
a where a.start1<=a.end1;
";
注:$sd,$ed是用户选择的时间
参考:http://www.cnblogs.com/hupengyin/p/6051145.html
时间: 2024-10-19 15:07:43