一个很难的SQL语句,大家帮忙!
select CoalMineName,MonUnitID,MonUnitName,MonUnitType,avg(Value) as 平均值,max(Value) as 最大值,Time=(select top 1 Time from ExcessRecord where CoalMineName=a.CoalMineName and MonUnitID=a.MonUnitID and MonUnitName=a.MonUnitName and MonUnitType=a.MonUnitType and Value=max(a.Value) and Time between '2007-4-21 00:00:00'and '2007-4-21 23:59:59') from ExcessRecord as a where Time between '2007-4-21 00:00:00'and '2007-4-21 23:59:5'and MonUnitType='10'or MonUnitType='14' or MonUnitType='11' or MonUnitType='13' or MonUnitType='63' or MonUnitType='60' or MonUnitType='15' or MonUnitType='12'group by CoalMineName,MonUnitID,MonUnitName,MonUnitType
查询出的结果是:
CoalMineName MonUnitID MonUnitName MonUnitType 平均值 最大值 最大值时刻
成鑫公司 2 总回风速<> 13 4.9199292291951808 6.6500000000000004 NULL
永红煤矿 1 总回一氧<> 14 0.3077142857142855 0.46999999999999997 NULL
宏业公司 1 总回负压<> 12 4.8355511976459466E-2 5.9999999999999998E-2 2007-04-21 08:49:04.000
它为什么把不符合时间条件的记录也给我查出来了呢?我就想查2007-04-21的。谁能帮我看一下