排除sql中的时间范围

时间:2018-03-17 12:11:24

标签: sql sql-server sql-server-2008

实际上我有一个表来存储电话的详细信息,我需要过滤掉第二天16:00:00到06:59:00之间进入IVR的电话整个月我使用了 BETWEEN 子句,但它包含了本月所有时间的详细信息。

#version 430
layout (local_size_x = 4, local_size_y = 4, local_size_z = 4) in;

uniform int lightCount;

const unsigned int clusterSize = 32;
const unsigned int clusterSquared = clusterSize * clusterSize;

struct LightInfo {
    vec4 color;
    vec3 position;
    float radius;
};

layout(std430, binding = 0) buffer occupancyGrid {
    int exists[];
};

layout(std430, binding = 2) buffer lightInfos
{
  LightInfo lights [];
};

layout(std430, binding = 1) buffer outputList {
    int indices[];
};

void main(){
    unsigned int clusterId = gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * clusterSize + gl_GlobalInvocationID.z * clusterSquared;

    if(exists[clusterId] == 0)
        return;

    //... not so relevant calculations

    unsigned int outIndexStart = clusterId * 9;
    unsigned int outOffset = 1;

    for(int i = 0; i < lightCount && outOffset < 9; i++){
        if(distance(lights[i].position, wordSpace.xyz) < lights[i].radius) {
            indices[outIndexStart + outOffset] = i;
            indices[outIndexStart]++;
            outOffset++;
        }
    }
}

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:4)

使用DATEPART()功能测试一天中的小时。在您的情况下,检查时间就足够了:

SELECT conversationId,
       conversationStart
  FROM [Customer].[dbo].[vw_Conversations]
  WHERE conversationStart BETWEEN '2018-01-01' AND '2018-02-01'
    AND DATEPART(hour, conversationStart) NOT BETWEEN 7 AND 15

答案 1 :(得分:2)

您只需要测试时间组件。我不确定你想要的日期范围,但查询是这样的:

SELECT conversationId, conversationStart
FROM Customer.dbo.[w_Conversations c
WHERE CONVERT(date, conversationStart) >= '2018-01-01' AND
      CONVERT(date, conversationStart) < '2018-02-01' AND
      (CONVERT(time, conversationStart) >= '16:00:00') OR
       CONVERT(time, conversationStart) < '07:00:00')
      );