主题:VFP 或 SQL 表中字段间替换的问题
张山99
[专家分:0] 发布于 2009-06-15 14:02:00
有一表A如附图
supplypart字段为零件编码,U_Price字段为单价
但一份表内有多个零件编码是重复的,重复的编码对应的单价稍有差别
请教如何将重复编码的单价取最小值重新全部赋上
最后更新于:2009-06-15 14:59:00
回复列表 (共4个回复)
沙发
sywzs [专家分:5650] 发布于 2009-06-15 14:42:00
这个方法笨一点,你可以试一试。supplypart是字符型,U_Price是数值型,没见到附图。
INDEX on supplypart+STR(U_Price,10,2) TO Sy
GO top
jh=supplypart
dj=U_Price
DO WHILE !EOF()
IF supplypart=jh
REPLACE U_Price WITH dj
ELSE
jh=supplypart
dj=U_Price
ENDIF
SKIP
ENDDO
板凳
张山99 [专家分:0] 发布于 2009-06-15 15:03:00
谢谢楼上的兄弟了
[img]http://vfp.sunyear.com.tw/files/0615_170.jpg[/img]
不会上传图片啊
3 楼
qjbzjp [专家分:8830] 发布于 2009-06-16 08:49:00
SELECT SUPPLYPART FROM AA GROUP BY 1 INTO CURS TMP
sele aa
FOR I =1 TO RECCOUNT("tmp")
MinPRICE=10000
GO i in tmp
mysup=tmp.SUPPLYPART
SCAN FOR SUPPLYPART=mysup
MinPRICE=min(u_price,MinPRICE)
ENDSCAN
REPLACE all U_price with MinPRICE for SUPPLYPART=mysup
NEXT
4 楼
琅拿度 [专家分:2820] 发布于 2009-06-16 10:42:00
呵呵,觉得可能楼主的一些结构安排不太合理,试试我的笨方法,数据多的话处理会快点:
select a
sort to temp1 on supplypar,u_price
use temp1 in 0
select temp1
index on supplypart+str(U_Price*100,10) TO px unique &&千万不能加ALLTRIM,没有空格就排不正确了
copy to temp2.dbf
set index to
dele file px.idx
use temp2 in 0
select temp2
scan
update A set a.u_price=temp2.u_price where a.supplypar=temp2.supplypar
endscan
select temp1
use
select temp2
use
dele file temp1
dele file temp2
我来回复