Home > Database > Mysql Tutorial > body text

sqlserver中将varchar类型转换为int型再进行排序的方法

WBOY
Release: 2016-06-07 18:07:09
Original
1108 people have browsed it

sql中把varchar类型转换为int型然后进行排序,如果我们数据库的ID设置为varchar型的 在查询的时候order by id的话

如果我们数据库的ID设置为varchar型的 在查询的时候order by id的话我们是不希望看到如下情况的。

我们可以把varchar转换为int 然后进行排序

一、
代码如下:
select * from yourtable order by cast(yourcol as int);

适用于SQLServer Oracle

二、
代码如下:
select * from yourtable order by convert(int,yourcol);

仅适用于SQLServer

作者 itmyhome

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template