当前位置: 代码迷 >> 高性能WEB开发 >> hql 日期字段排序的写法,该怎么解决
  详细解决方案

hql 日期字段排序的写法,该怎么解决

热度:800   发布时间:2014-02-27 01:51:40.0
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


查询表中数据,按年月日,时分秒排序,由于库中的时间字段精确到毫秒了,只能想到拆分了
但是降序排序后,得到的数据还是升序的
如果把后面的时、分、秒去掉,只保留前面的年、月、日则获取的数据是正确的(降序了)
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','') --20111205155448
把他们全部转化为数字
  相关解决方案