尋找資料 |
尚未結案
|
hc
一般會員 發表:9 回覆:5 積分:2 註冊:2005-10-14 發送簡訊給我 |
資料庫是用access 裡面有2個以上的資料表 假設其中之一的資料表有 日期,溫度(AM),溫度(PM) 等等的欄位
例如
日期 溫度(AM) 溫度(AM)
---------------------------------------------------------
2005/10/1 33.5 34.5
2005/10/2 32.6 34.2
2005/10/3 34.1 35.2
2005/10/4 33.8 34.1
接著在delphi 放入2個TDateTimePicker元件,1個查詢按鈕TBitBtn....那要寫個尋找功能,譬如時間從2005/10/1 ~ 2005/10/4 找出溫度最大值 35.2 請教各位大大怎麼做呢?
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi hc,
SQL Command : select min(Temperature) as minTemperature, max(Temperature) as maxTemperature from (select dt, AMTemperature as Temperature from table2 union all select dt, PMTemperature as Temperature from table2) where dt between :p_date1 and :p_date2 BitBtn1.OnClick : procedure TForm1.BitBtn1Click(Sender: TObject); begin ADOQuery3.close; ADOQuery3.Parameters.ParamByName('p_date1').Value := Trunc(DateTimePicker1.Date); ADOQuery3.Parameters.ParamByName('p_date2').Value := Trunc(DateTimePicker2.Date) 0.99999; ADOQuery3.Open; end;發表人 -
------
Fishman |
hc
一般會員 發表:9 回覆:5 積分:2 註冊:2005-10-14 發送簡訊給我 |
|
hc
一般會員 發表:9 回覆:5 積分:2 註冊:2005-10-14 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi hc,
1. select top 1 t2.* from (select id, dt, AMTemperature as Temperature from table2 union all select id, dt, PMTemperature as Temperature from table2) t1, table2 t2 where t2.id = t1.id and t1.dt between :p_date1 and :p_date2 order by t1.Temperature desc id is then UniqueKey for table table2 2. 可啊,但是若 QUERY 要花較多時間,或必須重新 QUERY 則不太適合 3.聯集,詳見以下說明: http://delphi.ktop.com.tw/topic.php?topic_id=46127 4. Trunc(2005/01/01 12:30:00) = 2005/01/01 00:00:00 2005/01/01 00:00:00 0.99999 = 2005/01/01 23:59:59 因此若是日期時間欄位,可以如此寫That's all folks !! Have fun !! ---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman |
hc
一般會員 發表:9 回覆:5 積分:2 註冊:2005-10-14 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |