注册 登录
编程论坛 VFP论坛

请教这个序号该怎么生成?先谢谢了!

bdx808 发布于 2023-05-31 08:11, 886 次点击
有个表csb,里面有部分数据,序号xh是数值型,想把xh分为xh1和xh2,结果如表jg一样,数据量大时无法手工一个一个写出来,请教各位大神,这个生成xh1和xh2的prg该怎么写?
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2023-5-31 08:12编辑过]

10 回复
#2
my23182023-05-31 08:53
说说xh,xh1,xh2的关系,这样大家才能帮你
#3
bdx8082023-05-31 09:06
就是每4行为一组,xh1的顺序不变,但成倍增加了,xh2是在xh1的基础上递增,但不是顺序递增,这个规律不好说,有些表达不力,请看一下这个图,我用彩色线标记了一下
只有本站会员才能查看附件,请 登录
#4
shizi02023-05-31 10:00
xh1=(Ceiling(xh/4)-1)*8+xh
xh2=xh1+iif(mod(xh,4)<3,6,2)
#5
bdx8082023-05-31 10:12
回复 4楼 shizi0
试了一下,还有些不一样
#6
fyyylyl2023-05-31 11:18
REPLACE ALL xh1 WITH Xh*2-IIF(Xh%4=0,4,Xh%4),Xh2 WITH Xh*2-IIF(Xh%4=0,4,Xh%4)+IIF(BETWEEN(Xh%4,1,2),6,2)


[此贴子已经被作者于2023-5-31 11:51编辑过]

#7
sdta2023-05-31 12:14
以下是引用fyyylyl在2023-5-31 11:18:40的发言:

REPLACE ALL xh1 WITH Xh*2-IIF(Xh%4=0,4,Xh%4),Xh2 WITH Xh*2-IIF(Xh%4=0,4,Xh%4)+IIF(BETWEEN(Xh%4,1,2),6,2)

正解

Xh2 WITH Xh*2-IIF(Xh%4=0,4,Xh%4)+IIF(BETWEEN(Xh%4,1,2),6,2)
可以简化为
Xh2 WITH Xh1+IIF(BETWEEN(Xh%4,1,2),6,2)

[此贴子已经被作者于2023-5-31 12:25编辑过]

#8
bdx8082023-05-31 14:12
多谢两位!!
#9
吹水佬2023-05-31 14:40
只有本站会员才能查看附件,请 登录

程序代码:

SELECT 4,1,2,3 FROM csb WHERE RECNO()==1 INTO ARRAY aXh1
SELECT 2,6,6,2 FROM csb WHERE RECNO()==1 INTO ARRAY aXh2
REPLACE ALL xh1 WITH 2*xh-aXh1[xh%4+1], xh2 WITH xh1+aXh2[xh%4+1]
SELECT * FROM csb
#10
bdx8082023-06-01 17:20
吹版的代码,我理解不了的正确,毋容置疑的正确(不过已经结过贴了)
#11
sdta2024-04-23 17:57
xh1 WITH Xh*2-IIF(Xh%4=0,4,Xh%4)
改为
xh1 with xh*2-1-mod(xh-1,4) && 少个IIF()判断,速度可以快点
速度可能会快点
1