Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在sql中提取指定时间间隔内的每个日期数据_Sql - Fatal编程技术网

在sql中提取指定时间间隔内的每个日期数据

在sql中提取指定时间间隔内的每个日期数据,sql,Sql,在上面的代码中,我为每个日期提取7到23的数据,工作正常。但是当我尝试从23到7提取数据时,它的相反部分无法得到结果。请向我提供解决方案 请查看上述内容的附加屏幕截图 SELECT * FROM #TempMatrixTable WHERE TIME >='07:00:00' and TIME <= '23:00:00' ORDER BY dateperiod 当我试图获取数据时,使用上述查询。由于23大于7,我没有得到任何行。可能的解决

在上面的代码中,我为每个日期提取7到23的数据,工作正常。但是当我尝试从23到7提取数据时,它的相反部分无法得到结果。请向我提供解决方案

请查看上述内容的附加屏幕截图

   SELECT * FROM #TempMatrixTable 
        WHERE  TIME >='07:00:00' and TIME <= '23:00:00' 
        ORDER BY dateperiod
当我试图获取数据时,使用上述查询。由于23大于7,我没有得到任何行。可能的解决方案是什么请帮助我

  SELECT * FROM #TempMatrixTable 
        WHERE  TIME >='23:00:00' and TIME <= '07:00:00' 
        ORDER BY dateperiod
当我能够获取数据时,使用上述查询。

我认为您想要或而不是,并且:


当你得到23到07之间的时间,你实际上得到了两个时间间隔;在23和24之间,以及在00和07之间:

SELECT *
FROM #TempMatrixTable 
WHERE TIME >='23:00:00' OR TIME <= '07:00:00' 
ORDER BY dateperiod;
当然,您不需要00和23.59边界,因为时间值不能超出这些边界:

select
  *
from
  #TempMatrixTable 
where
  TIME >='00:00:00' and TIME < '07:00:00' or
  TIME >='23:00:00' and TIME <= '23:59:99.9999'
order by
  dateperiod

如果您只是想反转所选的时间间隔,您可以将NOT放在要求反的表达式前面

什么时候

其中时间>='07:00:00'和时间='07:00:00'以及时间'07:00:00'和时间<'23:00:00'

select
  *
from
  #TempMatrixTable 
where
  TIME >='00:00:00' and TIME < '07:00:00' or
  TIME >='23:00:00' and TIME <= '23:59:99.9999'
order by
  dateperiod
select
  *
from
  #TempMatrixTable 
where
  TIME < '07:00:00' or
  TIME >='23:00:00'
order by
  dateperiod