读书人

hql 日期字段排序的写法,该怎么处理

发布时间: 2012-06-28 15:20:03 作者: rapoo

hql 日期字段排序的写法
SELECT year(indagatedate),month(indagatedate),day(indagatedate),datepart(hour,indagatedate),datepart(minute,indagatedate),datepart(second,indagatedate)
order by year(indagatedate),month(indagatedate),day(indagatedate),datepart(hour,indagatedate),datepart(minute,indagatedate),datepart(second,indagatedate) desc


查询表中数据,按年月日,时分秒排序,由于库中的时间字段精确到毫秒了,只能想到拆分了
但是降序排序后,得到的数据还是升序的
如果把后面的时、分、秒去掉,只保留前面的年、月、日则获取的数据是正确的(降序了)

[解决办法]

SQL code
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','') --20111205155448 

读书人网 >高性能WEB开发

热点推荐