简体   繁体   English

sql查询升序或降序

[英]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. 我同时使用ASCDESC两种方法,但都没有获得令人满意的结果。 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.

相关问题 在CodeIgniter中,如何在查询检索的同时检索sql查询并按升序或降序对其进行排序? - In CodeIgniter, how do I retrieve a sql query and order it by either ascending or descending order at the same time of query retrieval? PDO-按价格升序或降序 - PDO - order by price ascending or descending PHP按升序/降序排序不起作用 - PHP Order by Ascending/Descending not working PHP-如何通过升序或降序排序数据 - PHP - How to order data by ascending or descending Laravel-使用链接按升序和降序排列图像 - Laravel - Arranging images in ascending and descending order with links 如何在不使用PHP中的sort()函数或SQL中的ORDER BY的情况下使用名称值对表值进行升序和降序排序? - How to sort table values in ascending and descending with name value without using sort() function in PHP or ORDER BY in SQL? 创建一个按钮,用于对 MYSQL 查询进行升序和降序排序 - Create a button that will sort a MYSQL query ascending and descending 如何在古吉拉特语网站的选项标签中设置升序或降序 - How to set ascending or descending order in gujarati website's option tag 如何更改购物车页面上的自定义费用顺序(升序/降序)(woocommerce) - How to Change Custom Fee order (Ascending/Descending) on cart page (woocommerce ) 将字符串转换为php中的数组,输出然后按升序和降序输出 - Convert string to array in php, output it and then output in ascending and descending order
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM