日期:2014-05-16  浏览次数:20856 次

听ACMAIN_CHM建议,重新开贴列表结构求助,Access问题
两个表
DayReport表,日报表 
表结构如下:
EquipNo(数字) ReportDay(日期) Temp01Max(数字)Temp01MaxTime(日期) Temp01Min(数字)Temp01MinTime ....32路
-------------------------------------------------------------------------
1 2010年2月2日 25.2 2010-2-2 19:00:00 17.5 2010-2-2 06:00:00  
DataReceived表,数据接收表
表结构如下:
EquipNo(数字) Rdatadate(日期) Rtmp01(数字) Rtmp02(数字) Rtmp03.。。。Rtmp32  
--------------------------------------------------------
1 2010-2-2 19:23:00 18.3 17.6 16.6

(以上数据为Test数据)

  接下来我说一下实现目的,DayReport是日报表,DataReceived是接收数据的总表, 
DataReceived数据表要接受每天的每分钟来自各路传感器的实时数值信息及时间,存储起来,DayReport每天将前一天某个设备(对应Equipno=1)各路传感器的最值信息(对应Temp01Min)及对应出现的时间(对应DataReceived表的Rdatadate)存储起来,因为一共涉及32路数据(Temp01···Temp32),我每次只能在DataReceived 
接受总表中找出一路的最值信息及对应时间,第一次可直接将第1路的最值信息及时间insert into DayReport,

Insert Into [DayReport](EquipNo,ReportDay,Temp01Max,Temp01MaxTime) Select Equipno,Rdatadate,Max(RTmp01),Rdatadate From [DataReceived] Where Equipno=1 and DateDiff('d',Rdatadate,#2010-2-2#)=0 Group by Equipno,Rdatadate,RTmp01; 
------这条语句执行成功 

但从第2路开始,到32路,就必须用Update DayReport将最值信息,和最值对应时间的信息分别更新到DayReport表去,

Update DayReport 
Set DayReport.Temp01Min= dmin( 
'RTmp01','DataReceived','Equipno=1 AND DateDiff("d",[Rdatadate],#2/3/2010#)=0') 
Where Equipno=1 and DateDiff('d',ReportDay,#2010-2-3#)=0;
------这条语句执行成功 再次谢谢wwwb同学的大力帮助
同样还得将 Temp01Min的对应时间信息Update 到Dayreport表中去,此项至今不知如何构造SQL语句?????
  因为操作的路数比较多,执行的SQL语句也比较多,能有稍微便捷些的解决方案吗?或者用什么样的方法或语句效率能提升一些,请ACMAIN_CHM及各位仁兄不吝赐教,我将挥泪道谢!!! 
 


------解决方案--------------------
Update DayReport 
Set DayReport.Temp01Min= dmin( 
'RTmp01','DataReceived','Equipno=1 AND DateDiff("d",[Rdatadate],#2/3/2010#)=0') 
Where Equipno=1 and DateDiff('d',ReportDay,#2010-2-3#)=0;

更改RTmp01字段即可,JETSQL对UPDATE支持不好,用域函数解决,
OR
用DataReceived表生成查询,再与DayReport连接
------解决方案--------------------
SQL code
insert into DayReport(EquipNo,ReportDay,
    Temp01Max,Temp01MaxTime,
    Temp01Min,Temp01MinTime,
    Temp02Max,Temp02MaxTime,
    Temp02Min,Temp02MinTime,
    Temp03Max,Temp03MaxTime,
    Temp04Min,Temp04MinTime,
    ...
    Temp32Max,Temp32MaxTime,
    Temp32Min,Temp32MinTime
    )
select EquipNo,#2010-2-2# ,
    Temp01Max,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp01Max and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp01MaxTime,
    Temp01Min,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp01Min and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp01MinTime,
    Temp02Max,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp02Max and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp02MaxTime,
    Temp02Min,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp02Min and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp02MinTime,
    Temp03Max,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp03Max and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp03MaxTime,
    Temp04Min,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp04Min and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp04MinTime,
    ...                                                                                   
    Temp32Max,(select min(Rdatadate) from DataReceived where EquipNo=t.EquipNo and Rtmp01=t.Temp32Max and Rdatadate between #2010-2-2# and #2010-2-223:59;59#) as Temp3