統計資料庫裡的數量~ |
答題得分者是:Fishman
|
depblue
一般會員 發表:38 回覆:29 積分:13 註冊:2004-12-27 發送簡訊給我 |
我要寫一個程式去統計在某個區間中,各種規格所擁有的數量
情形如下:
我先從AA資料表中select出 ordno = (2,4,6,9,10)
在從ordno = (2,4,6,9,10)中統計A,B,C規格所擁有的數量 var a_r :array of string;
I :integer;
ordnos,m_ordno:string; SetLength(a_r,10);
ord1Qu.Last;
m_ordno := ord1QuORDNO.Value;
strpt260Frm.ord1Qu.First; For I:= 0 To 9 do
begin
if not ord1Qu.Eof then
begin
if m_ordno = ord1QuORDNO.Value then
a_r[I] := ord1QuORDNO.Value
else
a_r[I] := ord1QuORDNO.Value ',';
ord1Qu.Next;
end
else
break;
end;
ordnos := a_r[0] a_r[1] a_r[2] a_r[3] a_r[4] a_r[5] a_r[6]; with st1Qu do
begin
Close;
SQL.Add('select st_kind,sum(ord_s) as ord_s,sum(ord_wei) as ord_wei');
SQL.Add('from AA);
SQL.Add('where ordno in (:p_ordno)');
SQL.Add('group by st_kind);
Parameters.ParamByName('p_ordno').Value := ordnos;
Open;
end; 以上是我的做法,不過ordnos的結果是'2,4,6,9,10'
導致st1Qu.recordcount=0 (實際上是st1Qu.recordcount=0) 請問我要如何修改ㄚ @@
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi depblue, 請參考
http://delphi.ktop.com.tw/topic.php?topic_id=41823 並建議更改如下
... with st1Qu do begin Close; SQL.Add('select st_kind,sum(ord_s) as ord_s,sum(ord_wei) as ord_wei'); SQL.Add('from AA); SQL.Add('where ordno in (' ordnos ')'); // 假設 ordno 為數字型態 SQL.Add('group by st_kind); Open; end; ...---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |