sql中的降序日期 [英] Descending date in sql

查看:464
本文介绍了sql中的降序日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望日期符合dsc顺序,但是当我尝试查询时它显示如下



date

02/02/2015

01/01/2015

05/01/2015

06/01/2015



如何



我尝试过的事情:



这个我试过的是什么

acdochdr.postdate DESC



任何解决方案?

解决方案

< blockquote>你显示的顺序可能不完全是你的数据所包含的内容:没有降序排序顺序会完全按照那个顺序排列。



当你使用 ORDER BY myDateColumn DESC 子句,如果列是基于字符串而不是DATE或DATETIME,它可以产生看起来错误结果的内容,因为基于字符串的比较总是按字符工作基础,整个比较是基于第一对不同字符之间的差异。所以数字的排序顺序看起来很奇怪:

 1 
10
11
12
...
19
2
20
...



首先检查数据库并确保将所有内容存储在最合适的数据类型,然后再继续。


i want date in dsc order but when i tried query it shows like this

date
02/02/2015
01/01/2015
05/01/2015
06/01/2015

so how

What I have tried:

this is what i tried
acdochdr.postdate DESC

any solution?

解决方案

The order you show is probably not exactly what your data contained : no descending sort order will put exactly that list in exactly that order.

When you use an ORDER BY myDateColumn DESC clause, it can produce what look like the wrong results if the column is string based instead of DATE or DATETIME, because string based comparisons always work on a character by character basis, and the whole comparison is based on the difference between the first pair of different characters. So the sort order for numbers looks odd:

1
10
11
12
...
19
2
20
...


So start by checking your database and make sure you are storing everything in the most appropriate datatype before you go any further.


这篇关于sql中的降序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆