设定固定时间段:8.2---》8.5

SQL语句:两个时间区间段,只要有交集,就能筛选出来

也就是:两个时间段,只要有交集就能筛选出来:

下面的两个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是用户选择的时间

相关文章:

  • 2021-05-28
  • 2021-11-24
  • 2022-12-23
  • 2021-11-08
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-25
  • 2021-12-03
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案