可以用group by进行编组select cs_id, max(cq) from ... group by cs_id
Select max(a.cq) From xxx a,xxx b where a.cs_id=b.cs_id
能说的更具体一点吗,用length不行吗??
这是表结构吗?“,”是cq字段值的一部分吗? Select cs_id,Max(cq) From yourtable Group by cs_id 字符串也可以比较大小的
我试用程序,这样, ncount:数据的行数(可以获得); 每行字节数为18; s为整个字符串;var a:string for i:=o to ncount-1 do begin for j:=i to ncount-1 do a:=copy(s,i*18,9); b:=copy(s,i*18+12,4) if a = copy(s,j*18,11) then begin if copy(s,j*18,11)>b then b:=copy(s,j*18,11); 在下去不懂怎么写,求助啊, end; end;
这是表结构吗?“,”是cq字段值的一部分吗? Select cs_id,Max(cq) From yourtable Group by cs_id 字符串也可以比较大小的
我试用程序,这样, ncount:数据的行数(可以获得); 每行字节数为18; s为整个字符串;var a:string for i:=o to ncount-1 do begin for j:=i to ncount-1 do a:=copy(s,i*18,9); b:=copy(s,i*18+12,4) if a = copy(s,j*18,11) then begin if copy(s,j*18,11)>b then b:=copy(s,j*18,11); 在下去不懂怎么写,求助啊, end; end;
var a,b:string; i,j,p:integer; csid,cq:tstringlist; begin csid:=tstringlist.create; cq:=tstringlist.create;
for i:=o to ncount-1 do begin for j:=i to ncount-1 do a:=copy(s,i*18,9); b:=copy(s,i*18+12,4) p:=csid.indexof(a); if p>=0 then //已经存在,则比较,如果大,就替换掉 begin if b>cq.strings[p] then cq.strings[p]:=b; end else begin//不存在,添价到串中 csid.add(a); cq.add(b); end; end; end;//csid对应的cq中就是最大的cq
如果你用的是SQLSERVER,可以试一试下面的句子, select max(cq) from 表名 where cs_id='''+edit.text+'''如果用的是PARADOX,可用下面的方法 select * from 表名 order by cq where cs_id='''+edit.text+''' query.last strSql:=query.fieldbyname('cq').asstring; 如果真的要在数据方面发展的话最好把SQL与DELPHI结合起来。SQL学好了,可以省很多编程的步骤。其中,edit.text是你取的cs_id的值,还有不明白的就给我写信吧! [email protected]
不好意思,理解错你的意思了。 按照你的想法,我觉得应该是分组。 select cs_id,max(cq) from 表名 group by cs_id 你也可以试着把cs_id为关键字,那样,表中的cs_id可就是唯一的了
var a,b:string; i,j,p:integer; csid,cq:tstringlist; begin csid:=tstringlist.create; cq:=tstringlist.create;
for i:=o to ncount-1 do begin for j:=i to ncount-1 do a:=copy(s,i*18,9); b:=copy(s,i*18+12,4) p:=csid.indexof(a); if p>=0 then //已经存在,则比较,如果大,就替换掉 begin if b>cq.strings[p] then cq.strings[p]:=b; end else begin//不存在,添价到串中 csid.add(a); cq.add(b); end; end; end; 我觉得不错,不过我的意思是我想把里面cs_id 相同的写入到数据库中,也就是说在cs_id 相同时 cq最大的读入数据库,而如果不相同时,则都读入数据库, 读入数据库语句为 table.fieldbyname(cs_id).value:= 所选择的cs_id ; table.fieldbyname(cq).value:= 所选择的cq;
我现在程序如下,不知是否可行还在试var i,j,p:integer; a:string; b,c:single; begin for i := 0 to nCount-1 do begin try a:=copy(s,i*26+1,9); b:=strtofloat(Copy(s,i*26+21,4)); c:=strtofloat(copy(s,j*26+13,7)); except exit; end; begin for p:=0 to i do if a<>copy(s,i*26+1,9) then begin for j:=i to ncount-1 do begin if copy(s,J*26+1,9) = a then begin if strtofloat(Copy(s,j*26+21,4))>= b then begin b:=strtofloat(Copy(s,j*26+21,4)); c:=strtofloat(copy(s,j*26+13,7)); end; end; end; end else exit; main_form.Memo1.Lines.Add(a+floattostr(b)+floattostr(c) +#13#10); end; end;
Select cs_id,Max(cq)
From yourtable
Group by cs_id
字符串也可以比较大小的
ncount:数据的行数(可以获得);
每行字节数为18;
s为整个字符串;var
a:string
for i:=o to ncount-1 do
begin
for j:=i to ncount-1 do
a:=copy(s,i*18,9);
b:=copy(s,i*18+12,4)
if a = copy(s,j*18,11) then
begin
if copy(s,j*18,11)>b then
b:=copy(s,j*18,11);
在下去不懂怎么写,求助啊,
end;
end;
Select cs_id,Max(cq)
From yourtable
Group by cs_id
字符串也可以比较大小的
ncount:数据的行数(可以获得);
每行字节数为18;
s为整个字符串;var
a:string
for i:=o to ncount-1 do
begin
for j:=i to ncount-1 do
a:=copy(s,i*18,9);
b:=copy(s,i*18+12,4)
if a = copy(s,j*18,11) then
begin
if copy(s,j*18,11)>b then
b:=copy(s,j*18,11);
在下去不懂怎么写,求助啊,
end;
end;
Select cs_id,Max(cq)
From yourtable
Group by cs_id
字符串也可以比较大小的
select cs_id, max(cq) from table group by cs_id
信息 读入到数据库,
我要的是在CS_id 相同时,只要读入数据库 cq 最大的就好
a,b:string;
i,j,p:integer;
csid,cq:tstringlist;
begin
csid:=tstringlist.create;
cq:=tstringlist.create;
for i:=o to ncount-1 do
begin
for j:=i to ncount-1 do
a:=copy(s,i*18,9);
b:=copy(s,i*18+12,4)
p:=csid.indexof(a);
if p>=0 then //已经存在,则比较,如果大,就替换掉
begin
if b>cq.strings[p] then
cq.strings[p]:=b;
end
else
begin//不存在,添价到串中
csid.add(a);
cq.add(b);
end;
end;
end;//csid对应的cq中就是最大的cq
select max(cq) from 表名 where cs_id='''+edit.text+'''如果用的是PARADOX,可用下面的方法
select * from 表名 order by cq where cs_id='''+edit.text+'''
query.last
strSql:=query.fieldbyname('cq').asstring;
如果真的要在数据方面发展的话最好把SQL与DELPHI结合起来。SQL学好了,可以省很多编程的步骤。其中,edit.text是你取的cs_id的值,还有不明白的就给我写信吧!
[email protected]
按照你的想法,我觉得应该是分组。
select cs_id,max(cq) from 表名 group by cs_id
你也可以试着把cs_id为关键字,那样,表中的cs_id可就是唯一的了
a,b:string;
i,j,p:integer;
csid,cq:tstringlist;
begin
csid:=tstringlist.create;
cq:=tstringlist.create;
for i:=o to ncount-1 do
begin
for j:=i to ncount-1 do
a:=copy(s,i*18,9);
b:=copy(s,i*18+12,4)
p:=csid.indexof(a);
if p>=0 then //已经存在,则比较,如果大,就替换掉
begin
if b>cq.strings[p] then
cq.strings[p]:=b;
end
else
begin//不存在,添价到串中
csid.add(a);
cq.add(b);
end;
end;
end;
我觉得不错,不过我的意思是我想把里面cs_id 相同的写入到数据库中,也就是说在cs_id 相同时 cq最大的读入数据库,而如果不相同时,则都读入数据库,
读入数据库语句为
table.fieldbyname(cs_id).value:= 所选择的cs_id ;
table.fieldbyname(cq).value:= 所选择的cq;
i,j,p:integer;
a:string;
b,c:single; begin
for i := 0 to nCount-1 do
begin
try
a:=copy(s,i*26+1,9);
b:=strtofloat(Copy(s,i*26+21,4));
c:=strtofloat(copy(s,j*26+13,7));
except
exit;
end;
begin
for p:=0 to i do
if a<>copy(s,i*26+1,9) then
begin
for j:=i to ncount-1 do
begin
if copy(s,J*26+1,9) = a then
begin
if strtofloat(Copy(s,j*26+21,4))>= b then
begin
b:=strtofloat(Copy(s,j*26+21,4));
c:=strtofloat(copy(s,j*26+13,7));
end;
end;
end;
end
else
exit;
main_form.Memo1.Lines.Add(a+floattostr(b)+floattostr(c) +#13#10);
end;
end;