有三个表a,b和ca:
a1,a2,a3
1 001 233
2 002 sd3
3 001
...b:
b1,b2,b3
1 22 23
1 2s 11
1 23 2d
1 23 23
2 ss ss
2 32 wa
2 we 2s
3 ed ss2
3 s1 23
3 3d sa
...c:
c1, c2,c3
001 1
001 1
001 1
001 1
...在DBGrid或cxGrid或其他Grid控件里显示表c的数据!就是当表a1=1时,表b中b1=1的记录数有几条,那就在表c的c2=1中增加相应的记录数(c1=a2).
a1,a2,a3
1 001 233
2 002 sd3
3 001
...b:
b1,b2,b3
1 22 23
1 2s 11
1 23 2d
1 23 23
2 ss ss
2 32 wa
2 we 2s
3 ed ss2
3 s1 23
3 3d sa
...c:
c1, c2,c3
001 1
001 1
001 1
001 1
...在DBGrid或cxGrid或其他Grid控件里显示表c的数据!就是当表a1=1时,表b中b1=1的记录数有几条,那就在表c的c2=1中增加相应的记录数(c1=a2).
解决方案 »
- 初学delphi,想问问delphi要不要虚拟机之类的东西支持?
- 为什么 DBGridEH 下拉框不显示?
- Teechart做曲线图时,到否固定死每格表示1,而且格与格的距离不变,数据多时可以通过滚动条滚动显示???
- 怎么读取windows剪贴板里的图片
- 求救啊!关于不同数据库表的嵌套查询问题---急啊!!!!!1
- 请教各位高手出现BDE问题:Insufficient Memory for This Operation怎么办???
- 求ModelMaker 10 下载和对应可用的cr
- 单机版的数据库软件怎么备份、恢复数据库?拜托讲明白点,最好能用到progressbar组件
- TQuery的SQL属性长度是有限质的吗?
- 滑动面板(象NETANTS1.0中的那样)
- 鼠标在窗体上的 移入 和 移出 事件
- 如何对非日期字段进行按日期统计
"这里你描述的不清楚。用sql select嵌套就可以了啊。
i,j,counts1,counts2 : integer;
with Tquery.Create(application) do
try
close;
SQL.Clear;
SQL.Add( 'select a1,a2,count(*) as counts1 from a ');
open;
i := 0;
while not eof do
begin
if i < counts1 then
begin
a1 := FieldByName('a1').AsString;
a2 := FieldByName('a2').AsString;
with Tquery.Create(application) do
try
close;
SQL.Clear;
SQL.Add( 'select b1,count(b1) as counts2 from a,b where a1 = b1 group by b1 ');
open;
i := i + 1;
j := 0;
while not eof do
begin
if i < counts2 then
begin
with Tquery.Create(application) do
try
close;
SQL.Clear;
SQL.Add( 'insert into b values(a2,a1) ');
open;
j := j + 1;
next;
Finally
Close;
Free;
end;
end;
next;
end;
Finally
Close;
Free;
end;
end;
next;
end;
Finally
Close;
Free;
end;