mysql函数问题 例如我有如下表AA:
id ymdhms value
1 2012-09-10 00:00:00 1
2 2012-09-10 01:00:00 2
3 2012-09-10 02:00:00 3
.................................................................
我用select max(value),ymdhms from AA;select min(value),ymdhms from AA
分别查最大值和最小值,按其他数据库(oracle,sqlServer)的经验,这个ymdhms应该是最大值、最小值所在行的数据,也就是最大值发生时间;最小值发生之间,可是查出来时间是乱的,并没有对应上,求解决办法, ------最佳解决方案-------------------- select max(value),count(value),(select ymdhms from AA where value=(select max(value) from AA)) as ymdhms from AA.
这样呢 ------其他解决方案-------------------- 这样行不行嗯。select top 1 from AA order by value desc ------其他解决方案--------------------
我觉得还要查avg, count之类的和那个sql没关系吧?按要求查出来的value是只有一行记录对吧? ------其他解决方案-------------------- 这样子试试
select * from AA where value=(select max(value) from AA) or value=(select min(value) from AA); ------其他解决方案--------------------
有其它的办法么?? 给你看看我的hql
String hql = "select new znet.web.database.dto.SensorWarnStatisticsDto" +
"(o.sensorObj.sensorId, o.sensorObj.sensorName, o.sensorObj.positionInfo, o.sensorObj.sensorTypeObj.sensorTypeName," +
" o.status, o.sensorObj.sensorTypeObj.unit, count(o), max(o.maxValue), o.maxTime, avg(o.averageValue))" +
" from SensorWarn o where 1=1 and o.startTime>='" + startTime + "' and o.endTime<='" + endTime + "'";
if(!"".equals(status))
hql += " and o.status='" + status + "'";
hql += " group by o.sensorObj.sensorId order by o.sensorObj.sensorId"; ------其他解决方案--------------------