select data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead,ISNULL(waterLevel,0) AS waterLevel from data,stinfo where data.stid in(51) and data.stid=stinfo.stid And stinfo.WaterLevelSensor=1 and surveytime >='2008-11-4' and surveytime <='2008-12-5' and dtype='整点报文' order by surveytime
-->>
select data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead,ISNULL(waterLevel,0) AS waterLevel ,avg=avg(ISNULL(waterLevel,0))from data,stinfo where data.stid in(51) and data.stid=stinfo.stid And stinfo.WaterLevelSensor=1 and surveytime >='2008-11-4' and surveytime <='2008-12-5' and dtype='整点报文' order by surveytime这样?

解决方案 »

  1.   

    select data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead,avg(waterLevel) AS waterLevel 
    from data,stinfo 
    where data.stid in = 51 and data.stid=stinfo.stid And stinfo.WaterLevelSensor=1 and surveytime >='2008-11-4' and surveytime <='2008-12-5' and dtype='整点报文' 
    group by data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead
    order by surveytime
      

  2.   

    select data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead,avg(waterLevel) AS waterLevel 
    from data,stinfo 
    where data.stid = 51 and data.stid=stinfo.stid And stinfo.WaterLevelSensor=1 and surveytime >='2008-11-4' and surveytime <='2008-12-5' and dtype='整点报文' 
    group by data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead
    order by surveytime
      

  3.   

    谢谢,dawugui,你解决了我的问题,请问为什么加了avg函数后必须group by data.stid,stinfo.stname,stinfo.sttype,rectime,surveytime,waterhead
    我开始也用avg函数,但是group没有加这些报错!
      

  4.   

    在你的记错上我改成这样Avg(ISNULL(waterLevel,0)) AS waterLevel了,数据库为"null"的时候它显示为0,你写的这个如果为空就不显示了