請教更高深的SQL 指令問題 |
答題得分者是:timhuang
|
leee02
一般會員 發表:17 回覆:12 積分:5 註冊:2002-10-09 發送簡訊給我 |
請教一個SQL 指令問題: 我有一個資料庫,其內容如下範例: FDate FTime
---------------------------
2003/4/1 00:10:01 AM
2003/4/1 01:10:01 AM
2003/4/1 02:10:01 AM
2003/4/1 03:10:01 AM
2003/4/1 04:10:01 AM
2003/4/1 05:10:01 AM
2003/4/1 12:10:01 PM
2003/4/1 01:10:01 PM
2003/4/1 03:10:01 PM
2003/4/1 08:10:01 PM
2003/4/1 10:10:01 AM
2003/4/1 11:10:01 AM
2003/4/2 00:10:01 AM
2003/4/2 01:10:01 AM
2003/4/2 02:10:01 AM
2003/4/2 03:10:01 AM
2003/4/3 00:10:01 AM
2003/4/3 01:10:01 AM
2003/4/3 02:10:01 AM
2003/4/3 03:10:01 AM
......
我如果想要抓取2003/4/1 02:00:01 AM 至 2003/4/3 01:59:59 AM 這段其間的資料或許會更久,可能五天或十天這樣的期間,不知該如何下SQL指令。
|
Justmade
版主 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
|
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
|
leee02
一般會員 發表:17 回覆:12 積分:5 註冊:2002-10-09 發送簡訊給我 |
|
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
節錄一段 Local SQL Help :
Description Use the BETWEEN comparison predicate to compare a value to a value range. If the value is greater than or equal to the low end of the range and less than or equal to the high end of the range, BETWEEN returns a TRUE value. If the value is less than the low end value or greater than the high end value, BETWEEN returns a FALSE value. For example, the expression below returns a FALSE value because 10 is not between 1 and 5. 10 BETWEEN 1 AND 5 Use NOT to return the converse of a BETWEEN comparison. For example, the expression below returns a TRUE value. 10 NOT BETWEEN 1 AND 5 BETWEEN can be used with all non-BLOB data types, but all values compared must be of the same or a compatible data type. If one value is of an incompatible data type, convert that value with the CAST function to a compatible data type. Values used in a BETWEEN comparison may be column, literal, or calculated values. SELECT Saledate FROM Orders WHERE (Saledate BETWEEN "1/1/1988" AND "12/31/1988") |
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
Hi, 請試試: Select * from Table1 where
(FDate = '2003/4/1' and FTime >= '02:00:01' )
or
(FDate > '2003/4/1' and FDate < '2003/4/3')
or
(FDate = '2003/4/3' and FTime <= '01:59:59' ) 以此類推. 僅頭尾要定出時間範圍, 中間段定出日期範圍即可, 如:
抓取2003/4/1 02:00:01 AM 至 2003/4/10 01:59:59 AM
則可用: Select * from Table1 where
(FDate = '2003/4/1' and FTime >= '02:00:01' )
or
(FDate > '2003/4/1' and FDate < '2003/4/10')
or
(FDate = '2003/4/10' and FTime <= '01:59:59' )
|
leee02
一般會員 發表:17 回覆:12 積分:5 註冊:2002-10-09 發送簡訊給我 |
引言: Hi, 請試試: Select * from Table1 where (FDate = '2003/4/1' and FTime >= '02:00:01' ) or (FDate > '2003/4/1' and FDate < '2003/4/3') or (FDate = '2003/4/3' and FTime <= '01:59:59' ) 以此類推. 僅頭尾要定出時間範圍, 中間段定出日期範圍即可, 如: 抓取2003/4/1 02:00:01 AM 至 2003/4/10 01:59:59 AM 則可用: Select * from Table1 where (FDate = '2003/4/1' and FTime >= '02:00:01' ) or (FDate > '2003/4/1' and FDate < '2003/4/10') or (FDate = '2003/4/10' and FTime <= '01:59:59' )================================================ 感謝,這就是我要的答案。 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |