主题:解答 dean_andy
比如字段名A,B
字段内容 张三 103
李四 101
李四 104
张三 105
王五 106
李四 108
王五 107
输出结果:A B
张三 103,105
李四 101,104,108
王五 106,107
怎么用最简单的语句得出以上结果,求解!
set safety off
close all
clear
close all
sele * from 表1 ; &&&&&&&&&& 原始表
order by a,b into table b3.dbf
close all
sele recn() sx,* from b3.dbf into table b4.dbf
close all
sele a,count(allt(a)) gs from b4.dbf group by a into table b1.dbf
close all
sele a.*,b.gs from b4.dbf a,b1.dbf b where allt(a.a)==allt(b.a) order by a.sx into table b2.dbf
close all
sele a,b from b2.dbf where gs=1 into table c1.dbf
close all
sele a.a,allt(a.b)+','+allt(b.b) b from b2.dbf a,b2.dbf b ;
where allt(a.a)==allt(b.a) and a.gs=2 and b.gs=2 and a.sx<>b.sx ;
order by a.sx into table c2.dbf
close all
sele a,min(b) b from c2.dbf group by a into table c3.dbf
close all
sele a.a,allt(a.b)+','+allt(b.b)+','+allt(c.b) b from b2.dbf a,b2.dbf b,b2.dbf c ;
where allt(a.a)==allt(b.a) and allt(a.a)==allt(c.a) and a.gs=3 and b.gs=3 and c.gs=3 and ;
a.sx<>b.sx and a.sx<>c.sx and b.sx<>c.sx order by a.sx into table c4.dbf
close all
sele a,min(b) b from c4.dbf group by a into table c5.dbf
close all
use c5.dbf &&&&&&&&&&&&& 结果表
appen from c3.dbf
appen from c1.dbf
close all
erase b3.dbf
erase b4.dbf
erase b1.dbf
erase b2.dbf
erase c1.dbf
erase c2.dbf
erase c3.dbf
erase c4.dbf
close all
quit