标题:统计错误单词的次数
只看楼主
一彭ok
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2018-5-10
结帖率:68.97%
已结贴  问题点数:30 回复次数:4 
统计错误单词的次数
如图:今日错题.dbf

想用代码统计每个单词错误的次数,求解答(效果如图)

select.....from.......into......group by.........?
搜索更多相关主题的帖子: 统计 错误 单词 次数 into 
2018-08-17 22:40
shenkj001
Rank: 3Rank: 3
来 自:河南安阳
等 级:论坛游侠
威 望:9
帖 子:340
专家分:147
注 册:2005-5-23
得分:20 
&&用DO WHILE,试试下面代码:
CLOSE DATABASES
USE 今日错题.dbf ALIAS lcdbfb
IF FSIZE("错误次数")=0
ALTER table lcdbfb ADD  错误次数 c(2)
ENDIF
select 单词,count(单词) as cnts from lcdbfb GROUP BY 单词 INTO CURSOR lsybb
SELECT MAX(cnts) FROM lsybb INTO CURSOR lscsb
lccs=MAX_cnts
*?lccs
SELECT lcdbfb
S=0
DO while S<lccs
FOR I=1 TO RECCOUNT()
    GO I
    IF DELETE()
       LOOP
    ELSE
       OLDRECN=I
       单词1=ALLTRIM(单词)      
    ENDIF
    LOCATE REST FOR ALLTRIM(单词)==单词1
    NJS=0
    DO WHILE FOUND()
       NJS=NJS+1
       IF NJS>S  
  REPLACE 错误次数 WITH ALLTRIM(STR(NJS))
              ENDIF
       CONTINUE      
    ENDDO
    I=OLDRECN   
ENDFOR
S=S+1
ENDDO
CLOSE DATABASES
SELECT * FROM 今日错题.dbf INTO CURSOR lstj READWRITE
ALTER table lstj ADD  id c(2)
REPLACE ALL id WITH ALLTRIM(STR(RECNO()))
DELETE FROM lstj WHERE lstj.id NOT IN ( SELECT m2.mid  FROM (  SELECT 单词,max(id) AS mid FROM lstj   GROUP BY 单词 ) AS m2)
PACK
ALTER TABLE lstj DROP COLUMN id
COPY TO cctj
USE cctj
BROWSE  LAST
CLOSE ALL
QUIT

[此贴子已经被作者于2018-8-18 14:51编辑过]


shenkj001@
2018-08-18 02:32
shenkj001
Rank: 3Rank: 3
来 自:河南安阳
等 级:论坛游侠
威 望:9
帖 子:340
专家分:147
注 册:2005-5-23
得分:0 
或者用SCAN也行,试试下面代码:
CLOSE DATABASES
USE 今日错题.dbf ALIAS lcdbfb
IF FSIZE("错误次数")=0
ALTER table lcdbfb ADD  错误次数 c(2)
ENDIF
SELECT 单词,000 错误次数 FROM lcdbfb INTO CURSOR lsybb READWRITE
 INDEX ON 单词 TO 单词
 N=1
 CXM=""
 SCAN
     IF allt(单词)==CXM
         N=N+1
     ELSE
         N=1
     ENDIF
     REPLACE 错误次数 WITH N
     CXM=allt(单词)
 ENDSCAN
CLOSE DATABASES
SELECT * FROM 今日错题.dbf INTO CURSOR lstj READWRITE
ALTER table lstj ADD  id c(2)
REPLACE ALL id WITH ALLTRIM(STR(RECNO()))
DELETE FROM lstj WHERE lstj.id NOT IN ( SELECT m2.mid  FROM (  SELECT 单词,max(id) AS mid FROM lstj   GROUP BY 单词 ) AS m2)
PACK
ALTER TABLE lstj DROP COLUMN id
SELECT * FROM lstj
CLOSE ALL
QUIT

[此贴子已经被作者于2018-8-18 17:56编辑过]


shenkj001@
2018-08-18 14:47
一彭ok
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2018-5-10
得分:0 
回复 2楼 shenkj001
谢谢大神回答,不过这代码统计结果好像有问题
2018-08-18 16:59
shenkj001
Rank: 3Rank: 3
来 自:河南安阳
等 级:论坛游侠
威 望:9
帖 子:340
专家分:147
注 册:2005-5-23
得分:10 
回复 4楼 一彭ok
你把数据发过来,再试试
CLOSE DATABASES
USE 今日错题.dbf ALIAS lcdbfb
IF FSIZE("错误次数")=0
ALTER table lcdbfb ADD  错误次数 c(2)
ENDIF
SELECT 单词,COUNT(单词) as 错误次数 FROM 今日错题.dbf GROUP BY 单词  INTO TABLE &ldtj
sele * from &ldtj


[此贴子已经被作者于2018-8-18 19:42编辑过]


shenkj001@
2018-08-18 17:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-489282-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.226552 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved