 |
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
bx1166
註冊時間: 2011-12-06 文章: 273
第 16 樓
|
發表於: 星期三 四月 08, 2015 11:07 pm 文章主題: |
|
|
Sele 1
Use original.dbf &your dbf name here
Copy to tempfile
Sele 1
Use tempfile
Copy to mtemp for type='C'
Dele for type='C'
Pack
Sele 2
Use mtemp
Go top &&or scan endscan
Do while .not. Eof()
Sele 1
Locate for date=b.date .and. Item=b.item .and. No=(0-b.no) .and. (.not. Deleted())
If .not. Eof()
Dele
End if
Sele 2
Skip
End do
Sele 1
Pack
Brow
存成prg
Run 這個prg
這樣看看結果對不對跑跑看
bx1166 在 星期五 四月 10, 2015 5:33 pm 作了第 4 次修改 |
|
回頂端 |
|
 |
yctsai
註冊時間: 2003-04-11 文章: 180
第 17 樓
|
發表於: 星期三 四月 08, 2015 11:36 pm 文章主題: |
|
|
1.我比較喜歡用select 指令來挑資料
2.select * from x where id+... IN (select id+... from cursor y) into cursor z
所以我用....代表這裡...是需要研究的
3.也許這樣
select * from x where type='C' into table y
select * from x where id+name+se_no+date+item+lo+alltrim(str(no)) IN (select id+name+se_no+date+item+lo+alltrim(str(no*-1)) from y) into table z
select * from x where id+name+se_no+date+item+loalltrim(str(no)) NOT IN (select id+name+se_no+date+item+lo+alltrim(str(no)) from z) into table zz |
|
回頂端 |
|
 |
sthuang66
註冊時間: 2014-04-27 文章: 178
第 18 樓
|
發表於: 星期四 四月 09, 2015 12:24 am 文章主題: |
|
|
to bx1166
您的方法跑完只有消掉type=C,第五第六兩筆!第一第二還在 |
|
回頂端 |
|
 |
sthuang66
註冊時間: 2014-04-27 文章: 178
第 19 樓
|
發表於: 星期四 四月 09, 2015 12:46 am 文章主題: |
|
|
to yctsai
select * from x where type='C' into table y
select * from x where id+name+se_no+date+item+lo+alltrim(str(no)) IN (select id+name+se_no+date+item+lo+alltrim(str(no*-1)) from y) into table z
select * from x where id+name+se_no+date+item+lo+alltrim(str(no)) NOT IN (select id+name+se_no+date+item+lo+alltrim(str(no)) from z) into table zz
您的方法我操作後會剩下4,5,6三筆資料!1,2,3筆去掉了
我附上檔案供參考http://vfp.sunyear.com.tw/files/x_406.xls
因為DBF不能PO!所以貼上XLS
sthuang66 在 星期四 四月 09, 2015 2:27 am 作了第 1 次修改 |
|
回頂端 |
|
 |
sthuang66
註冊時間: 2014-04-27 文章: 178
第 20 樓
|
發表於: 星期四 四月 09, 2015 2:13 am 文章主題: |
|
|
TO yctsai
我參考你之前寫的B. 用SUM方法好像可以了
----------------------------------------------------------------
SE='ID+NAME+SE_NO+DATE+ITEM+LO'
SELECT *,&SE AS SEQ FROM X INTO TABLE X1
SELECT ID,NAME,SE_NO,DATE,ITEM,LO,SEQ,SUM(NO) AS NO FROM X1 GROUP BY ID,NAME,SE_NO,DATE,ITEM,LO,SEQ INTO TABLE X2
SELECT * FROM X2 WHERE NO<>0 INTO TABLE X3
QUIT |
|
回頂端 |
|
 |
bx1166
註冊時間: 2011-12-06 文章: 273
第 21 樓
|
發表於: 星期四 四月 09, 2015 7:18 am 文章主題: |
|
|
sthuang66 寫到: | to bx1166
您的方法跑完只有消掉type=C,第五第六兩筆!第一第二還在 |
No是負値,改正一下 |
|
回頂端 |
|
 |
sthuang66
註冊時間: 2014-04-27 文章: 178
第 22 樓
|
發表於: 星期四 四月 09, 2015 10:33 am 文章主題: |
|
|
TO bx1166
謝謝你的關注與指教
----------------------------------------------------------------------------------------
Sele 1
Use original.dbf &your dbf name here
Copy to tempfile
Sele 1
Use tempfile
Copy to mtemp for type='C'
Dele for type='C'
Pack
Sele 2
Use mtemp
Go top &&or scan endscan
Do while .not. Eof()
Sele 1
Locate for date=b.date .and. Item=b.item .and. No=(0-b.no)
If .not. Eof()
Dele
Endif
Sele 2
Skip
Enddo
Sele 1
Pack
Brow
------------------------------------------------------------
第二筆還是沒有去掉 |
|
回頂端 |
|
 |
bx1166
註冊時間: 2011-12-06 文章: 273
第 23 樓
|
發表於: 星期四 四月 09, 2015 12:34 pm 文章主題: |
|
|
修正一下,第一跟第二筆其實是一樣,所以得再修正此處 |
|
回頂端 |
|
 |
perry
註冊時間: 2014-07-20 文章: 203
第 24 樓
|
發表於: 星期四 四月 09, 2015 12:42 pm 文章主題: |
|
|
您不是測Select了???
sele id,name,se_no,date,item,lo,sum(no) as no from Yourdbf grou by id,name,date,item,lo into curs x1
sele * from x1 wher no#0 into curs x2
brow
clos all
clea all |
|
回頂端 |
|
 |
bx1166
註冊時間: 2011-12-06 文章: 273
第 25 樓
|
發表於: 星期四 四月 09, 2015 1:15 pm 文章主題: |
|
|
我覺得select無法解決問題,現在只有幾筆,一旦重複到上幾千幾萬筆時,如何挑出多筆重複的? |
|
回頂端 |
|
 |
perry
註冊時間: 2014-07-20 文章: 203
第 26 樓
|
發表於: 星期四 四月 09, 2015 1:30 pm 文章主題: |
|
|
其實不會有問題!!
會出問題是在 type 是否是 'C' 和 '3' 相對
sele id,name,se_no,date,item,lo,sum(no) as no from Yourdbf wher type='C' or type='3' grou by id,name,date,item,lo into curs x1 |
|
回頂端 |
|
 |
perry
註冊時間: 2014-07-20 文章: 203
第 27 樓
|
發表於: 星期四 四月 09, 2015 5:13 pm 文章主題: |
|
|
若用 scan 換個角度或許效率較高
set dele on
sele 0
sele * from yourdbf wher type ='3' into dbf x1
sele 0
sele * from yourdbf wher type='C' into dbf x2
sele x1
go top
scan
sele x2
go top
if eof()
exit
endi
loca for id=x1.id and se_no=x1.se_no and date=x1.date and item=x1.item and lo=x1.lo
if found()
dele
sele x1
dele
endi
sele x1
ends |
|
回頂端 |
|
 |
sthuang66
註冊時間: 2014-04-27 文章: 178
第 28 樓
|
發表於: 星期四 四月 09, 2015 8:20 pm 文章主題: |
|
|
TO PERRY
--------------------------------------------------------
set dele on
sele 0
sele * from yourdbf wher type ='3' into dbf x1
sele 0
sele * from yourdbf wher type='C' into dbf x2
sele x1
go top
scan
sele x2
go top
if eof()
exit
endi
loca for id=x1.id and se_no=x1.se_no and date=x1.date and item=x1.item and lo=x1.lo
if found()
dele
sele x1
dele
endi
sele x1
ends
----------------------------------------------------
執行後x1好像沒有變
-----------------------------------------------------
TO BX1166
SELECT 的語法我參照YCTSAI可以了
並且PERRY也寫出來跟我一樣可以消掉第一與第二筆
-------------------------------------------
SE='ID+NAME+SE_NO+DATE+ITEM+LO'
SELECT *,&SE AS SEQ FROM X INTO TABLE X1
SELECT ID,NAME,SE_NO,DATE,ITEM,LO,SEQ,SUM(NO) AS NO FROM X1 GROUP BY ID,NAME,SE_NO,DATE,ITEM,LO,SEQ INTO TABLE X2
SELECT * FROM X2 WHERE NO<>0 INTO TABLE X3
QUIT |
|
回頂端 |
|
 |
perry
註冊時間: 2014-07-20 文章: 203
第 29 樓
|
發表於: 星期四 四月 09, 2015 9:20 pm 文章主題: |
|
|
其實 BX1166 考慮的如果資料若不是 id+se_no+date+item+lo 一天一筆,
用 select * grou by 方式會有問題!!
而用 scan 可避免問題發生!!
下面我測有效,不知 sthuang66 為何說無效???
代碼: |
set dele on
sele 0
sele * from kt wher type='3' into dbf ktx1
sele 0
sele * from kt wher type='C' into dbf ktx2
sele ktx1
go top
scan
sele ktx2
go top
if eof()
exit
endi
loca for id=ktx1.id and se_no=ktx1.se_no and ;
date=ktx1.date and item=ktx1.item and ;
lo=ktx1.lo and no+ktx1.no=0 &&確保沒刪錯
if found()
dele
sele ktx1
dele
else
sele ktx1
endi
ends
sele ktx1
go top
brow
|
|
|
回頂端 |
|
 |
bx1166
註冊時間: 2011-12-06 文章: 273
第 30 樓
|
發表於: 星期四 四月 09, 2015 10:02 pm 文章主題: |
|
|
畢竟我們不是當事人,我見論壇裡面問題形形色色,解決問題就好,
我更喜歡看別人的問答,可以學習到
至於vfp 是否有未來,只要大家繼續用,就有機會𨒂續它的生命
我還見過還堅持dos,clipper的呢。 |
|
回頂端 |
|
 |
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|