0

我有近 15000 个数据行,第一列包含格式的日期: 2012-05-10 09:00:00.000

我需要按年、月、日、小时对这些数据进行排序,例如:

         2012-05-10 09:00:00.000
         2012-05-10 10:00:00.000
         2012-05-10 11:00:00.000
         2012-05-10 12:00:00.000
         2012-05-11 09:00:00.000
         2012-05-11 10:00:00.000
         2012-05-11 11:00:00.000
         2012-05-11 12:00:00.000
         2012-06-01 02:00:00.000
         2012-06-01 03:00:00.000
         2012-06-01 04:00:00.000
         2012-06-01 05:00:00.000

执行此操作的当前SQL查询如下:

SELECT MIN(Datetime) GROUP BY DATEPART(M,jmusa_LOG1.DateTime),DATEPART(D,jmusa_LOG1.DateTime),DATEPART(HH,jmusa_LOG1.DateTime) HAVING MIN(jmusa_LOG1.DateTime) NOT IN(SELECT DateTime FROM AverageRawData)

ORDER BY DATEPART(M,jmusa_LOG1.DateTime),DATEPART(D,jmusa_LOG1.DateTime),DATEPART(HH,jmusa_LOG1.DateTime)

4

1 回答 1

1

你正在描述一个正常的日期排序,所以你可以这样做:

select MyDate
from AverageRawData
order by MyDate

如果您不想重复,请添加DISTINCT如下:

select distinct MyDate
from AverageRawData
order by MyDate

如果这不符合您的要求,请提供用于生成输出示例的示例数据。

于 2012-07-03T19:07:51.870 回答