線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:869
推到 Plurk!
推到 Facebook!

請教更高深的SQL 指令問題

答題得分者是:timhuang
leee02
一般會員


發表:17
回覆:12
積分:5
註冊:2002-10-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-10 22:30:02 IP:210.201.xxx.xxx 未訂閱
請教一個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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-10 22:41:18 IP:218.16.xxx.xxx 未訂閱
不同資料庫的語法稍有不同,簡單來說就是在 where 裡 把 FDate 變成字串 FTime 變成字串 來與你的條件作字串對比,要記得使用年月日時分秒的格式來對比就可以了。若你不知你使用的資料庫要甚樣做,可說出你的資料庫等大家幫你。
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-10 22:43:50 IP:218.32.xxx.xxx 未訂閱
請看藍字 ↓     資料庫種類繁多, 記得先說用啥資料庫喔
leee02
一般會員


發表:17
回覆:12
積分:5
註冊:2002-10-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-10 23:03:52 IP:210.201.xxx.xxx 未訂閱
引言: 請看藍字 ↓ 資料庫種類繁多, 記得先說用啥資料庫喔
=================================== 我用的資料庫是PARADOX DB
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-04-10 23:41:20 IP:218.32.xxx.xxx 未訂閱
節錄一段 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-04-10 23:59:47 IP:61.221.xxx.xxx 未訂閱
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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-04-11 00:22:35 IP:210.201.xxx.xxx 未訂閱
引言: 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' )
================================================ 感謝,這就是我要的答案。
系統時間:2024-06-27 1:25:41
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!