如何用vfp sql语句直接实现下面功能
假设ls dbf表中的数据如下:bmddm sxkmdm xkzh
020100 1 11
020100 1 12
020100 1 11
020100 5 51
020100 5 52
经过SQL语句处理后,ss dbf表中的数据将是:
bmddm sxkmdm xkzh ksrs
020100 1 11,12 3
020100 5 51,52 2
VFP SQL语句如何实现
Create Cursor ls(bmddm c(6),sxkmdm i,xkzh i) Insert Into ls Values('020100',1,11) Insert Into ls Values('020100',1,12) Insert Into ls Values('020100',1,11) Insert Into ls Values('020100',5,51) Insert Into ls Values('020100',5,52) Select bmddm ,sxkmdm,Count(sxkmdm) As ksrs,fn1(bmddm,sxkmdm) As xkzh From ls Group By bmddm ,sxkmdm Proc fn1 Lparameters tc1,tc2 Local lcString lcString = '' Select Distinct xkzh From ls Where bmddm =tc1 And sxkmdm =tc2 Into Curs tmp1 Sele tmp1 Scan All lcString = lcString + ','+Trans(xkzh) Endscan Return Subs(lcString,2)
Create Cursor hz (bmddm V(6),sxkmdm N(1) ,xkzh V(12), ksrs N(4)) INDEX ON bmddm+TRANSFORM(sxkmdm) TAG px Create Cursor ls (bmddm V(6),sxkmdm N(1) ,xkzh V(12)) Insert Into ls Values('020100',1,'11') Insert Into ls Values('020100',1,'12') Insert Into ls Values('020100',1,'11') Insert Into ls Values('020100',5,'51') Insert Into ls Values('020100',5,'52') SET RELATION TO bmddm+TRANSFORM(sxkmdm) INTO hz SELECT ls SCAN IF FOUND("hz") REPLACE xkzh WITH xkzh+","+ls.xkzh, ksrs WITH ksrs+1 IN hz ELSE INSERT INTO hz VALUES (ls.bmddm, ls.sxkmdm, ls.xkzh, 1) ENDIF ENDSCAN SET RELATION TO SELECT hz SET ORDER TO BROWSE