注册 登录
编程论坛 VFP论坛

如何用vfp sql语句直接实现下面功能

snowofdream 发布于 6 天前 21:24, 222 次点击
假设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语句如何实现
3 回复
#2
easyppt5 天前 09:20
程序代码:
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)
  
#3
sdta5 天前 18:39
XKZH能重复吗
需要用SQL命令解决这个问题吗,用VFP自身命令就能解决这个问题
程序代码:
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
#4
snowofdream5 天前 22:59
谢谢楼上的解答,过程程序我已实现,就是想了解VFP有没有类似group_concat()这样的函数。或者sqlserver for xml path这样的,还是谢谢
1