---
title: "sql时间段查询语句"
author: "wyl232"
date: "2008-05-28T13:56:33Z"
tags: ["F#", "SQL"]
slug: "sql"
draft: false
lastmod: "2008-05-28T13:56:33Z"
id: 197843
url: "https://wyl232.iteye.com/blog/197843"
---

需求如下：

   检索传入的变量date是否在数据库中存在24个小时范围的记录，即传入时间变量已知，时间段未知

```
select cpc.* from fh_ad_webmaster f , fh_salereportforms_cpc cpc where f.id=cpc.adwebmaster and cpc.click_ip='192.168.110.121' and cpc.adwebmaster='ff8080811a294c0c011a294dbd270001' and cpc.click_time <= CAST('date' AS DATETIME) and (select DATE_ADD(cpc.click_time, Interval 1 DAY))>=CAST('date' AS DATETIME)
date 是传入的参数字符串 当前日期
```