Ⅰ sql 如何查詢日期在一定范圍內的數據
select * from 表 where 日期欄位>='開始日期' and 日期欄位<='截止日期' and convert(char(8),日期欄位,108)>='開始時間' and convert(char(8),日期欄位,108)<='截止時間'。
SELECT * FROM 表明 WHERE 日期欄位名 BETWEEN '20130101' AND '20130130'。
例如:
select * from tb1 where dDate>='2010-11-05' and dDate<='2010-11-15'
and convert(char(8),dDate,108)>='8:00:00' and convert(char(8),dDate,108)<='9:00:00'.
select * from table1where year(d)=2010 and month(d)=7 and day(d) between 1 and 31
and (Datepart(hour,d)>=22 or Datepart(hour,d)<6)
(1)sql查詢指定日期范圍數據擴展閱讀:
SQL查詢日期:
今天的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())=0
昨天的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())=1
7天內的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())<=7
30天內的所有數據:select * from 表名 where DateDiff(dd,datetime類型欄位,getdate())<=30
本月的所有數據:select * from 表名 where DateDiff(mm,datetime類型欄位,getdate())=0
本年的所有數據:select * from 表名 where DateDiff(yy,datetime類型欄位,getdate())=0
參考資料:SQL_網路
Ⅱ sql語句怎麼查詢在某日期的數據
你可以採用這個方式:
datediff(day,cardinfo.opendate,getdate())<=7
其中day表示天數cardinfo.opendate是表中的一個欄位,getdate()是獲取當前日期
day也可以換的
詳細可以聯系我
Ⅲ sql 查詢時間、日期范圍內的數據
SELECT*
FROMTableName
WHERECONVERT(DATETIME,CONVERT(VARCHAR,日期列)+''+CONVERT(VARCHAR,時間列))BETWEEN'2012-1-107:00:00'AND'2012-1-410:00:00'
Ⅳ SQL語句查詢特定時間段的數據怎麼寫
SQL伺服器:
Select*fromtablewhere'2008-7-1'和'2008-12-31'
訪問:
從表中選擇發生日期>#2008-7-1#和發生日期<#2008-12-31#
就是這樣:注意,SQLserver中的日期和訪問有一點不同。
(4)sql查詢指定日期范圍數據擴展閱讀:
SQL查詢日期語句
Select*fromShopOrderwheredatediff(week,ordTime,getdate()-1)=0//查詢第一年的日期
Select*fromShopOrder,其中datediff(day,ordTime,getdate()-1)=0//查詢當天的所有數據
SELECT * FROM A where datediff(d,datetime,getdate()) <=30 //前30天
SELECT * FROM A WHERE DATEDIFF(m, shijian, GETDATE()) <=1 //上個月
搜索當天記錄的其他方法:
SELECT*
FROMj_GradeShop
其中(GAddTimeBETWEENCONVERT(datetime,LEFT(GETDATE(),10)+'00:00:00.000'))
並轉換(datetime,LEFT(GETDATE(),10)+'00:00:00.00.000')+1)
由GAddTime指定的訂單
Ⅳ sql語句如何查日期欄位的某天的數據
1、創建測試表,
create table test_date(id varchar2(20), v_date date);
Ⅵ sql怎麼查詢指定時間段內包含某個內容的所有數據
sql server
SELECT * FROM 表名 WHERE datepart(hour,tm)=12 and datepart(minute,tm)=0 and datepart(second,tm)=0 and datediff(month,tm,getdate())<1
access:用now()代替getdate()
oracle:用sysdate代替getdate()
Ⅶ 資料庫的日期區間查詢方法。
access中有個mid函數,可以用來截取字元串或者日期。
select * from 表名 where mid([TestTime],5,10) ='04/19/2013'其中,5代表截取的開始位置,從左數,10代表截取的長度。
資料庫的日期區間查詢有兩種情況:
1:查詢給定時間在開始時間列與結束時間列范圍中數據;
2:查詢日期列在開始時間列與結束時間列范圍中數據。
第一種:<,>, <= , >=
select * from 表名 where 日期列 >= to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss')
and t.日期列 <= to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
第二種 between and
select * from 表名 where 日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd
hh24:mi:ss')and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
(7)sql查詢指定日期范圍數據擴展閱讀:
SQL資料庫語句:
創建資料庫:
CREATE DATABASE database-name。
刪除資料庫:
drop database dbname。
創建新表:
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)。
刪除新表:
drop table tabname。
增加一個列:
Alter table tabname add column col type。
添加主鍵:
Alter table tabname add primary key(col)。
刪除主鍵:
Alter table tabname drop primary key(col)。
創建索引:
create [unique] index idxname on tabname(col….)。
刪除索引:
drop index idxname。
創建視圖:
create view viewname as select statement。
刪除視圖:
drop view viewname。
參考資料來源:網路-sql語句大全
Ⅷ sql server 日期范圍查詢
SELECT * FROM 表明 WHERE 日期欄位名 BETWEEN '20130101' AND '20130130'
或者:
SELECT * FROM 表明 WHERE 日期欄位名 BETWEEN CONVERT(datetime,'2013-01-01',120) AND CONVERT(datetime,'2013-01-30',120)
(8)sql查詢指定日期范圍數據擴展閱讀:
注意事項
在寫按時間段查詢的sql語句的時候 一般我們會這么寫查詢條件:
where date>='2010-01-01' and date<='2010-10-1'。
但是在實執行Sql時些語句會轉換成這樣:
where date>='2010-01-01 0:00:00' and date<='2010-10-1:0:00:00',再看這個條件的話,就會有些明白,那就是'2010-10-1 0:00:00' 之後的數據例如('2010-10-1:08:25:00')查不到,也就是說2010-10-1的數據查不到。
修改查詢條件為:
where date>='2010-01-01' and date<='2010-10-1 23:59:59' 或 where date>='2010-01-01' and date<='2010-10-2'。
某個表某個欄位是Datetime型 以"YYYY-MM-DD 00:00:00" 存放
Ⅸ MYSQL資料庫,怎樣查詢一個時間范圍內,每個時間點內的數據
1.假設資料庫中有一個名為TestTest的表。表格內容如下圖所示。
Ⅹ 如何在SQL中按時間段查詢數據
sql server:
select * from 表 where 發生日期>'2008-7-1' and 發生日期<'2008-12-31'
access:
select * from 表 where 發生日期>#2008-7-1# and 發生日期<#2008-12-31#
這樣就可以了,注意sql server與access中的日期有一點不一樣。
(10)sql查詢指定日期范圍數據擴展閱讀:
sql查詢日期語句
select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0 //查詢當天日期在一周年的數據
select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 //查詢當天的所有數據
SELECT * FROM A where datediff(d,datetime,getdate()) <=30 //前30天
SELECT * FROM A WHERE DATEDIFF(m, shijian, GETDATE()) <=1 //上一月
查詢當天記錄另類的方法:
SELECT *
FROM j_GradeShop
WHERE (GAddTime BETWEEN CONVERT(datetime, LEFT(GETDATE(), 10) + ' 00:00:00.000')
AND CONVERT(datetime, LEFT(GETDATE(), 10) + ' 00:00:00.000') + 1)
ORDER BY GAddTime DESC