请教,如何把dianfei表变成dianfei1表,按月份的计算用电量?
如何编程把以下dianfei表变成dianfei1表,dianfei表中b1,b2,b3,b4,b5表示每个用户的5个电表,表示该月份月底抄表的读数,如要计算10月份的用电量,就要用10月底抄表的读数减去9月底抄表的读数,如28.9-25.1=3.3等等,请各位老师指导、赐教,感谢。
CLOSE ALL
CLEAR
SET SAFETY off
Create TABLE dianfei (cs n (6,0),cname c (30),cyear c(6), cmonth c(2),b1 n(8,2),b2 n(8,2),b3 n(8,2),b4 n(8,2),b5 n(8,2))
Insert Into dianfei Values (0,'abc','2012','9',25.1,26.1,29.2,12.1,18.2)
Insert Into dianfei Values (0,'abc','2012','10',28.9,38.5,32.5,18.5,19.9)
Insert Into dianfei Values (0,'abc','2012','11',29.1,40.5,36.1,20.1,29.8)
Insert Into dianfei Values (0,'abc','2012','12',30.2,46.5,40.9,26.2,39.5)
Insert Into dianfei Values (0,'abc','2013','1',32.8,58.5,46.5,29.9,45.8)
Insert Into dianfei Values (0,'abc','2013','2',36.5,65.5,56.8,36.5,55.5)
Insert Into dianfei Values (0,'abd','2012','9',39.2,36.8,32.5,58.5,52.2)
Insert Into dianfei Values (0,'abd','2012','10',42.8,46.8,36.8,66.5,62.5)
Insert Into dianfei Values (0,'abd','2012','11',45.8,52.8,46.5,76.5,72.6)
Insert Into dianfei Values (0,'abd','2012','12',55.5,56.9,56.2,85.5,82.5)
Insert Into dianfei Values (0,'abd','2013','1',58.9,66.8,66.5,95.2,92.6)
Insert Into dianfei Values (0,'abd','2013','2',65.8,76.2,76.9,105.2,105.6)
USE dianfei
BROWSE
Create TABLE dianfei1 (cs n (6,0),cname c (30),cyear c(6), cmonth c(2),b1 n(8,2),b2 n(8,2),b3 n(8,2),b4 n(8,2),b5 n(8,2))
Insert Into dianfei1 Values (0,'abc','2012','10',3.8,12.4,3.3,6.4,1.7)
Insert Into dianfei1 Values (0,'abc','2012','11',0.2,2,3.6,1.6,9.9)
Insert Into dianfei1 Values (0,'abc','2012','12',1.1,6,4.8,6.1,9.7)
Insert Into dianfei1 Values (0,'abc','2013','1',2.6,12,5.6,3.7,6.3)
Insert Into dianfei1 Values (0,'abc','2013','2',3.7,7,10.3,6.6,9.7)
Insert Into dianfei1 Values (0,'abd','2012','10',3.6,10,4.3,8,10.3)
Insert Into dianfei1 Values (0,'abd','2012','11',3,6,9.7,10,10.1)
Insert Into dianfei1 Values (0,'abd','2012','12',9.7,4.1,9.7,9,9.9)
Insert Into dianfei1 Values (0,'abd','2013','1',3.4,9.9,10.3,9.7,10.1)
Insert Into dianfei1 Values (0,'abd','2013','2',6.9,9.4,10.4,10,13)
USE dianfei1
BROWSE
[解决办法]
Create Table dianfei (cs N (6,0),cname c (30),cyear c(6), Cmonth c(2),b1 N(8,2),b2 N(8,2),b3 N(8,2),b4 N(8,2),b5 N(8,2))
Insert Into dianfei Values (0,'abc','2012','9',25.1,26.1,29.2,12.1,18.2)
Insert Into dianfei Values (0,'abc','2012','10',28.9,38.5,32.5,18.5,19.9)
Insert Into dianfei Values (0,'abc','2012','11',29.1,40.5,36.1,20.1,29.8)
Insert Into dianfei Values (0,'abc','2012','12',30.2,46.5,40.9,26.2,39.5)
Insert Into dianfei Values (0,'abc','2013','1',32.8,58.5,46.5,29.9,45.8)
Insert Into dianfei Values (0,'abc','2013','2',36.5,65.5,56.8,36.5,55.5)
Insert Into dianfei Values (0,'abd','2012','9',39.2,36.8,32.5,58.5,52.2)
Insert Into dianfei Values (0,'abd','2012','10',42.8,46.8,36.8,66.5,62.5)
Insert Into dianfei Values (0,'abd','2012','11',45.8,52.8,46.5,76.5,72.6)
Insert Into dianfei Values (0,'abd','2012','12',55.5,56.9,56.2,85.5,82.5)
Insert Into dianfei Values (0,'abd','2013','1',58.9,66.8,66.5,95.2,92.6)
Insert Into dianfei Values (0,'abd','2013','2',65.8,76.2,76.9,105.2,105.6)
Browse
Create Table dianfei1 (cs N (6,0),cname c (30),cyear c(6), Cmonth c(2),b1 N(8,2),b2 N(8,2),b3 N(8,2),b4 N(8,2),b5 N(8,2))
Select dianfei
Scan
lcName=Alltrim(cname)
ldDate=Date(Val(cyear),Val(Cmonth),1)
lcYear=Transform(Year(Gomonth(ldDate,-1)))
lcMonth=Transform(Month(Gomonth(ldDate,-1)))
Scatter Name oRecord
Select * Into Cursor t1 From dianfei Where Alltrim(cname)=lcName And Alltrim(cyear)=lcYear And Alltrim(Cmonth)=lcMonth
If _Tally>0
Insert Into dianfei1 Values (0,oRecord.cname,oRecord.cyear,oRecord.Cmonth,oRecord.b1-t1.b1,oRecord.b2-t1.b2,oRecord.b3-t1.b3,oRecord.b4-t1.b4,oRecord.b5-t1.b5)
Endif
Endscan
Select dianfei1
Browse