如何從同一個TADOQuery中多層搜尋 |
答題得分者是:Fishman
|
evoneliu
一般會員 發表:12 回覆:10 積分:4 註冊:2004-10-21 發送簡訊給我 |
Dear :以下為一個餐別歷史檔… 有個spcmealspcmealadoquery,property SQL陳述如下:
select * from spcmeal
where spcmeal.mealordersn=:e_mealordersn(訂餐單號) and spcmeal.cabin =:e_cabin(艙別)and spcmeal.amount<>'0' 有個spcmealAspcmealadoquery,property SQL陳述如下:
select max(modifydate) modifydate from spcmeal
where mealordersn=:e_mealordersn(訂餐單號) and cabin=:e_cabin(艙別) and prodcode=:e_prodcode(產品代號) and spcmeal.amount<>'0'
訂餐單號A0001:-->1頭等艙-->A產品-->modifydate(2005/01/09)
-->B產品-->modifydate(2005/01/10) 訂餐單號A0002:-->1頭等艙-->A產品-->modifydate(2005/01/09)
-->B產品-->modifydate(2005/01/10) 有個DBGrid datasource為:spcmealds,如果我想這個DBGrid呈現的是:
訂餐單號(A0001)、艙別(1頭等艙)、B產品(希望呈現modifydate為最後修改日,而非是A產品時) 及
訂餐單號(A0002)、艙別(1頭等艙)、B產品(希望呈現modifydate為最後修改日,而非是A產品時),我如何秀出這兩筆資料而不會各出現出A產品呢?以下為我寫的程式,若只寫第一段時會出現四筆資料,我第二段寫了,但是不知如果套用第一段,還請各位幫忙,謝謝! procedure TEditIocSpcForm.calc;
var modifydate:string;
begin
spcmealadoquery.close;
spcmealadoquery.parameters.parambyname('e_mealordersn').value := trim(mealordersnedit.text);
spcmealadoquery.parameters.parambyname('e_cabin').value := copy(trim(cabinedit.text),1,2);
spcmealadoquery.open;
=======================================第一段結束
with spcmealadoquery do begin
spcmealAadoquery.close;
spcmealAadoquery.parameters.parambyname('e_mealordersn').value := trim(mealordersnedit.text);
spcmealAadoquery.parameters.parambyname('e_cabin').value := copy(trim(cabinedit.text),1,2);
spcmealAadoquery.parameters.parambyname('e_prodcode').value := copy(trim(spccombobox.text),1,10);
spcmealAadoquery.open;
modifydate:= datetimetostr(spcmealAadoquerymodifydate.value) ;
end;
=======================================第二段結束
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi evoneliu, Do below SQL work !?
select * from spcmeal s where s.mealordersn = :e_mealordersn and s.cabin = :e_cabin and s.amount <> '0' and s.modifydate = (select max(t.modifydate) from spcmeal t where t.mealordersn = s.mealordersn and t.cabin = s.cabin and t.amount <> 0)---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman |
evoneliu
一般會員 發表:12 回覆:10 積分:4 註冊:2004-10-21 發送簡訊給我 |
dear :謝謝您的回覆,不過,問題難在於說,我要先利用spcmealspcmealadoquery的訂餐單號及艙別這"兩"個key值,抓出四筆資料
訂餐單號(A0001)、艙別(1頭等艙)、A產品
訂餐單號(A0001)、艙別(1頭等艙)、B產品
訂餐單號(A0002)、艙別(1頭等艙)、A產品
訂餐單號(A0002)、艙別(1頭等艙)、B產品,再利用
spcmealAspcmealadoquery的訂餐單號、艙別、及產品別這"三"個key值將我要的
訂餐單號(A0001)、艙別(1頭等艙)、B產品
訂餐單號(A0002)、艙別(1頭等艙)、B產品,留下,將A產品排除
如此可能無法用您所提供的方式秀出來說…還請各位高手幫忙…
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi evoneliu, How about this !?
select * from spcmeal s where s.amount <> '0' and s.modifydate = (select max(t.modifydate) from spcmeal t where t.mealordersn = s.mealordersn and t.cabin = s.cabin and t.amount <> 0)---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman |
evoneliu
一般會員 發表:12 回覆:10 積分:4 註冊:2004-10-21 發送簡訊給我 |
dear :正確來說,應該要新增"產品"的key是吧!親愛的Fishman,你已經大大解決了我疑惑了,超級感謝你的!該怎麼感謝你呢?祝你雞年大大發財囉!再次感謝!
select *
from spcmeal s
where s.mealordersn =:e_mealordersn
and s.cabin =:e_cabin
and s.amount <> '0'
and s.modifydate = (select max(t.modifydate)
from spcmeal t
where t.mealordersn = s.mealordersn
and t.cabin = s.cabin
and t.prodcode = s.prodcode //add
and t.amount <> 0)
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |