首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

请问,怎么编程把tt1表按规定时段变成 tt2表

2012-04-09 
请教,如何编程把tt1表按规定时段变成 tt2表?请教各位老师,如何编程把以下tt1表规定时段变成 tt2表SET DATE

请教,如何编程把tt1表按规定时段变成 tt2表?
请教各位老师,如何编程把以下tt1表规定时段变成 tt2表

SET DATE TO ansi
  SET CENTURY on
  SET SAFETY off
  CREATE table tt1 (cname c(6),cyear c(6), cmonth c(6),nnewsal n (9,2))
  INSERT INTO tt1 VALUES ("hans", "1998","2",300)
  INSERT INTO tt1 VALUES ("hans", "1998","3",300)
  INSERT INTO tt1 VALUES ("hans", "1998","4",300)
  INSERT INTO tt1 VALUES ("hans", "1998","5",300)
  INSERT INTO tt1 VALUES ("hans", "1998","6",300)
  INSERT INTO tt1 VALUES ("hans", "1998","7",1400)
  INSERT INTO tt1 VALUES ("hans", "1998","8",1400)
  INSERT INTO tt1 VALUES ("hans", "1998","9",1400)
  INSERT INTO tt1 VALUES ("hans", "1998","10",1400)
  INSERT INTO tt1 VALUES ("hans", "1998","11",1400)
  INSERT INTO tt1 VALUES ("hans", "1998","12",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","1",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","2",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","3",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","4",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","5",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","6",1400)
  INSERT INTO tt1 VALUES ("hans", "1999","7",1500)
  INSERT INTO tt1 VALUES ("hans", "1999","8",1500)
  INSERT INTO tt1 VALUES ("hans", "1999","9",1500)
  INSERT INTO tt1 VALUES ("hans", "1999","10",1500)
  INSERT INTO tt1 VALUES ("hans", "1999","11",1500)
  INSERT INTO tt1 VALUES ("hans", "1999","12",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","1",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","2",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","3",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","4",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","5",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","6",1500)
  INSERT INTO tt1 VALUES ("hans", "2000","7",5000)
  INSERT INTO tt1 VALUES ("hans", "2000","8",5000)
  INSERT INTO tt1 VALUES ("hans", "2000","9",5000)
  INSERT INTO tt1 VALUES ("hans", "2000","10",5000)
  INSERT INTO tt1 VALUES ("hans", "2000","11",5000)
  INSERT INTO tt1 VALUES ("hans", "2000","12",5000)
  INSERT INTO tt1 VALUES ("hans", "2001","1",5000)
   
   
  INSERT INTO tt1 VALUES ("dick", "1999","5",200)
  INSERT INTO tt1 VALUES ("dick", "1999","6",200)
  INSERT INTO tt1 VALUES ("dick", "1999","7",800)
  INSERT INTO tt1 VALUES ("dick", "1999","8",800)
  INSERT INTO tt1 VALUES ("dick", "1999","9",800)
  INSERT INTO tt1 VALUES ("dick", "1999","10",800)


  INSERT INTO tt1 VALUES ("dick", "1999","11",800)
  INSERT INTO tt1 VALUES ("dick", "1999","12",800)
  INSERT INTO tt1 VALUES ("dick", "2000","1",800)
  INSERT INTO tt1 VALUES ("dick", "2000","2",800)
  INSERT INTO tt1 VALUES ("dick", "2000","3",800)
  INSERT INTO tt1 VALUES ("dick", "2000","4",800)
  INSERT INTO tt1 VALUES ("dick", "2000","5",800)
  INSERT INTO tt1 VALUES ("dick", "2000","6",800)
  INSERT INTO tt1 VALUES ("dick", "2000","7",1500)
  INSERT INTO tt1 VALUES ("dick", "2000","8",1500)
  INSERT INTO tt1 VALUES ("dick", "2000","9",1500)
  INSERT INTO tt1 VALUES ("dick", "2000","10",1500)
  INSERT INTO tt1 VALUES ("dick", "2000","11",1500)
  INSERT INTO tt1 VALUES ("dick", "2000","12",1500)
  INSERT INTO tt1 VALUES ("dick", "2001","1",1500)
  brow
   
  CREATE table tt2 (cname c(6), date1 d ,date2 d, nnewsal n (9,2))
  
  INSERT INTO tt2 VALUES ("hans", {^1998-2-1},{^1998-6-30},300) 
  INSERT INTO tt2 VALUES ("hans", {^1998-7-1},{^1999-6-30},1400)
  INSERT INTO tt2 VALUES ("hans", {^1999-7-1},{^2000-6-30},1500)
  INSERT INTO tt2 VALUES ("hans", {^2000-7-1},{^2001-1-31},5000)

  INSERT INTO tt2 VALUES ("dick", {^1999-5-1},{^1999-6-30},200)
  INSERT INTO tt2 VALUES ("dick", {^1999-7-1},{^2000-6-30},800)
  INSERT INTO tt2 VALUES ("dick", {^2000-7-1},{^2001-1-31},1500)  
   
  Brow

说明:对tt1表 按名字、按规定的时间段归纳,时间段是这样的,按每年的7月1日至次年的6月30日为一段,如tt1表中,该名字(hans)的第一个时间不是7月1日的,该时间为开始时间(1998-2),则第一段是1998-2-1至1998-6-30,第二段是1998-7-1至1999-6-30,第三段是1999-7-1至2000-6-30,而,tt1表中,hans的最后时间是2001-1,那么,第四段是2000-7-1至2001-1-31;
dick的分段如此类推。
请老师们赐教,感谢


[解决办法]

SQL code
Set Date To AnsiSet Century OnSet Safety OffCLOSE DATABASESCreate Table tt1 (cname c(6),cyear c(6), Cmonth c(6),nnewsal N (9,2))Insert Into tt1 Values ("hans", "1998","2",300)Insert Into tt1 Values ("hans", "1998","3",300)Insert Into tt1 Values ("hans", "1998","4",300)Insert Into tt1 Values ("hans", "1998","5",300)Insert Into tt1 Values ("hans", "1998","6",300)Insert Into tt1 Values ("hans", "1998","7",1400)Insert Into tt1 Values ("hans", "1998","8",1400)Insert Into tt1 Values ("hans", "1998","9",1400)Insert Into tt1 Values ("hans", "1998","10",1400)Insert Into tt1 Values ("hans", "1998","11",1400)Insert Into tt1 Values ("hans", "1998","12",1400)Insert Into tt1 Values ("hans", "1999","1",1400)Insert Into tt1 Values ("hans", "1999","2",1400)Insert Into tt1 Values ("hans", "1999","3",1400)Insert Into tt1 Values ("hans", "1999","4",1400)Insert Into tt1 Values ("hans", "1999","5",1400)Insert Into tt1 Values ("hans", "1999","6",1400)Insert Into tt1 Values ("hans", "1999","7",500)Insert Into tt1 Values ("hans", "1999","8",500)Insert Into tt1 Values ("hans", "1999","9",1200)Insert Into tt1 Values ("hans", "1999","10",1200)Insert Into tt1 Values ("hans", "1999","11",1200)Insert Into tt1 Values ("hans", "1999","12",1200)Insert Into tt1 Values ("hans", "2000","1",1200)Insert Into tt1 Values ("hans", "2000","2",1200)Insert Into tt1 Values ("hans", "2000","3",500)Insert Into tt1 Values ("hans", "2000","4",500)Insert Into tt1 Values ("hans", "2000","5",500)Insert Into tt1 Values ("hans", "2000","6",500)Insert Into tt1 Values ("hans", "2000","7",500)Insert Into tt1 Values ("hans", "2000","8",500)Insert Into tt1 Values ("hans", "2000","9",500)Insert Into tt1 Values ("hans", "2000","10",500)Insert Into tt1 Values ("hans", "2000","11",500)Insert Into tt1 Values ("hans", "2000","12",500)Insert Into tt1 Values ("hans", "2001","1",500)Insert Into tt1 Values ("dick", "1999","5",200)Insert Into tt1 Values ("dick", "1999","6",200)Insert Into tt1 Values ("dick", "1999","7",800)Insert Into tt1 Values ("dick", "1999","8",800)Insert Into tt1 Values ("dick", "1999","9",800)Insert Into tt1 Values ("dick", "1999","10",800)Insert Into tt1 Values ("dick", "1999","11",800)Insert Into tt1 Values ("dick", "1999","12",800)Insert Into tt1 Values ("dick", "2000","1",800)Insert Into tt1 Values ("dick", "2000","2",800)Insert Into tt1 Values ("dick", "2000","3",800)Insert Into tt1 Values ("dick", "2000","4",800)Insert Into tt1 Values ("dick", "2000","5",800)Insert Into tt1 Values ("dick", "2000","6",800)Insert Into tt1 Values ("dick", "2000","7",1500)Insert Into tt1 Values ("dick", "2000","8",1500)Insert Into tt1 Values ("dick", "2000","9",1500)Insert Into tt1 Values ("dick", "2000","10",1500)Insert Into tt1 Values ("dick", "2000","11",1500)Insert Into tt1 Values ("dick", "2000","12",1500)Insert Into tt1 Values ("dick", "2001","1",1500)Create Table tt2 (cname c(6), date1 d ,date2 d, nnewsal N (9,2))Select tt1Go TopDO WHILE !EOF()    m.date1=Date(Val(CYEAR),Val(Cmonth),1)    Do While !Eof()        Scatter Memv        IF !EOF()            SKIP        endif        If !cname==m.cname or nnewsal<>m.nnewsal OR VAL(cmonth)=7            IF RECNO()>1                Skip -1            endif            m.date2=Date(Val(CYEAR),Val(Cmonth),Day(Gomonth(Date(Val(CYEAR),Val(Cmonth),1)-Day(Date(Val(CYEAR),Val(Cmonth),1))+1,1)-1))            SELECT tt2            APPEND blank            Replace cname With m.cname,;            date1 With m.date1,;            date2 WITH m.date2,;            nnewsal With m.nnewsal            SELECT tt1            IF !EOF()                SKIP            ENDIF            EXIT        Endif    EnddoenddoSELECT tt2BROWSE 


[解决办法]
这样吧,用下面的代码试试:

SQL code
*-- vfp9 代码CREATE table tt1 (cname c(6),cyear c(6), cmonth c(6),nnewsal n (9,2))...Select cname, nnewsal, Gomonth(Date(Val(cYear),Val(Cmonth),1),-6) As dd ;    from tt1 Into Cursor tt01Select cname, nnewsal, dd, Year(dd) As yy, 0000 As grp ;    from tt01 Into Cursor tt02 ReadwriteUse In tt01*-- 按 cname, dd, nnewsal 分段LocateScatter Name oRecSkipnGrp = oRec.grpScan Rest    If (nnewsal <> oRec.nnewsal) Or (yy <> oRec.yy) Or (cname <> oRec.cname)        Scatter Name oRec        nGrp = nGrp + 1    Endif    Replace Next 1 grp With nGrpEndscan*-- 统计结果Select cname, Gomonth(Min(dd),6) As dd1, Gomonth(Max(dd),7)-1 As dd2, Max(nnewsal) As nnewsal ;    from tt02 Group By grp, cname Into Table tt2Use In tt02 

热点排行