如何从升序中选择数字 [英] How to select numbers from ascending order
本文介绍了如何从升序中选择数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从SQL DB中按升序获取数字。我有一个名为DATE的列,我需要从数据库中选择不同的值。
i尝试了ORDER BY ASC,它给了1,10,11,111 ..就像我想要获取不同的值,如1,2,3,4,5,6,7,8,9,10,11 ......
在第二个查询中,如果我删除了它,那么它工作正常。
请协助获取我明确的价值
我尝试过的事情:
I am trying to get numbers from ascending order from SQL DB.I have a column called DATE and i need to select the distinct values from the database.
i tried the ORDER BY ASC and it give 1,10,11,111.. like that i want to take fetch the distinct values like 1,2,3,4,5,6,7,8,9,10,11 ...
in the second query if i remove the distinct then it works fine.
please assist to get me the distinct values
What I have tried:
select distinct Date from Daily ORDER BY CAST(Date as unsigned) ASC
select distinct Date from Daily ORDER BY Date * 1 ASC
推荐答案
您的日期
列可能是字符串/ varchar,因此字符串排序。
如果您正在使用MS SQL Server执行:
YourDate
column is probably a string/varchar hence the string ordering.
If you are using MS SQL Server do :
select distinct Date from Daily ORDER BY CAST(Date as int) ASC
这篇关于如何从升序中选择数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文