[英]sql query ascending or descending order
In my project I want to one query which is perform kms wise ASC|DESC query 在我的项目中,我想执行一个查询,即执行kms明智的ASC | DESC查询
My Query Is: 我的查询是:
select p_kms from Places where place_type='1' ORDER BY p_kms DESC
My Out is : 我的输出是:
p_kms
81
71
70
602
52
493
272
245
2049
1968
1948
1852
1813
1811
1807
1771
1758
174
1737
125
125
123
107
1035
Please let me know what I can do to solve this query. 请让我知道如何解决此查询。 I use both ways
ASC
and DESC
but not getting a satisfying result. 我同时使用
ASC
和DESC
两种方法,但都没有获得令人满意的结果。 How can I display p_KMS
in ASC
| 如何在
ASC
显示p_KMS
DESC
mode(ORDER BY p_KMS ASC|DESC)
When you create an index on a column or number of columns in MS SQL Server (I'm using version 2005), you can specify that the index on each column be either ascending or descending. DESC
mode(ORDER BY p_KMS ASC|DESC)
在MS SQL Server中(我使用的是2005版)在列或列数上创建索引时,可以指定每列的索引是升序还是降序。 I'm having a hard time understanding why this choice is even here. 我很难理解为什么这个选择仍然存在。 Using binary sort techniques, wouldn't a lookup be just as fast either way?
使用二进制排序技术,两种方式的查找都不会一样快吗? What difference does it make which order I choose?
我选择哪个顺序有什么不同?
Try this, 尝试这个,
ORDER BY p_kms * 1 DESC
will convert it to a number since it seems to be a text value. 会将其转换为数字,因为它似乎是文本值。 Or use
或使用
ORDER_BY cast(p_kms as unsigned) DESC
Check the table definition and change it. 检查表定义并进行更改。 You can change the data type to int like this
您可以像这样将数据类型更改为int
ALTER TABLE your_table MODIFY COLUMN p_kms int;
I assume that p_kms
is a varchar. 我假设
p_kms
是一个varchar。 So you would have to cast it to a number when ordering: 因此,您在订购时必须将其转换为数字:
select p_kms from Places where place_type='1' ORDER BY cast(p_kms as unsigned) DESC
Your query is right, But you want to change field "p_kms" as integer, 您的查询是正确的,但是您想将字段“ p_kms”更改为整数,
ALTER TABLE Places MODIFY COLUMN p_kms int;
Hope u got it :) Enjoy :) 希望你能得到:)享受:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.