获取sql server中表中max(hourvalue)的相应日期

时间:2011-07-13 15:05:44

标签: sql sql-server-2008

 SELECT [Id]
  ,[Date]
  ,[Condition]
         FROM [CRESULTS]
 where condition = 'abc'

我需要找到hour13的maxvalue和相应的日期,到目前为止我写的查询是有效的,但是还有其他任何改变的想法吗?

  SELECT top 1 max(abs([Hour13])) as hour13,date
  FROM CRESULTS where condition ='a' and Date between '2011-05-16' and '2011-07-10'
    group date
   order by hour13 desc

1 个答案:

答案 0 :(得分:2)

此处您不需要MAX

SELECT  TOP 1
        ABS(hour13) AS abs_hour13,
        datefield
FROM    cresults
WHERE   condition = 'a'
        AND datefield BETWEEN '2011-05-16' AND '2011-07-10'
ORDER BY
        abs_hour13 DESC