VFP 行记录转列记录

作者在 2015-02-18 02:33:32 发布以下内容
Note 行转列
clear all
create cursor t2 (学号 c(4),姓名 c(8),课目 c(10),成绩 n(3))
insert into t2 values ("1001","张三","数学",102)
insert into t2 values ("1001","张三","语文",120)
insert into t2 values ("1002","李四","数学",119)
insert into t2 values ("1002","李四","语文",108)

select distinct 课目 from t2 into array ajg

* 创建临时表结构及索引
lcstr=""
for lnI=1 to alen(ajg,1)
    lcstr=lcstr+iif(empty(lcstr),"",",")+alltrim(ajg[lnI,1])+" N(3)"
endfor
create cursor t4 (学号 c(4),姓名 c(8),&lcstr)
index on 学号+姓名 tag xhxm
* 结束 *

* 数据处理
select t2
set relation to 学号+姓名 into "t4"
scan
    km=alltrim(t2.课目)
    if found("t4")
        replace (km) with t2.成绩 in "t4"
    else
        insert into t4 (学号,姓名,&km) values (t2.学号,t2.姓名,t2.成绩)
    endif
endscan
set relation to
select t4
browse

* 结束 *
数据表问题 | 阅读 2607 次
文章评论,共1条
定燃民每(游客)
2018-04-04 18:58
1
游客请输入验证码
浏览402060次