dkfr.net
当前位置:首页 >> SQL中截取数字的前两位进行排序 >>

SQL中截取数字的前两位进行排序

在排序order by的时候,把你这个 to_char(字段) 一下就行,转成字符串排序就好了

select * from 表名 where code like '%[2013]%' order by cast(substring(code,charindex(']',code)+1,len(code)-charindex(']',code)) as int) desc 这样试试

--MSSQL,楼上那个肯定排不出你的效果select * from 表order by case SUBSTRING(字段,2,1) when '一' then 1when '二' then 2when '三' then 3when '四' then 4when '五' then 5when '六' then 6when '七' then 7when '八' then 8when '九' then ...

SELECT * FROM t3 ORDER BY CAST (LEFT(name,patindex('%[a-z,A-Z]%',right(name,len(name)-patindex('%[0-9]%',name)))) AS INT) ,SUBSTRING(NAME,patindex('%[a-z,A-Z]%',right(name,len(name)-patindex('%[0-9]%',name)+1)),1 ) ,CAST(RIGHT(...

如果数字都是小于10的,可以直接order by,按照字符规则排序就是你想要的这个。 如果数字有两位以上的,这时候11会排在2的前面,如果想数字按照数字的规则排序,字母按照字母的规则排序,需要根据条件将数字和字母分别查询出来进行排序,然后使...

根据你的要求: select * from (select 编号,时间,row_number() over (partition by 编号order by 时间) num from t_d_accountbank)t where t.num

select * from ( select row_number() over(partition by '分组' order by '日期') as rownum -- 排序并分组 , * -- 所需显示的字段 from 表 ) as T where T.rownum = 1 对每组的数据按日期排序并加上行号 取出时只取行号为1,也就是第一条数据。

--SQL Server 2000 select top (5) * from ( select top 15 * from 表 order by 排序列 desc ) as a order by 排序列 desc --SQL Server 2005,2008,2008R2,2012通用方法 select * from ( select *,row_number() over (order by 排序列 desc) as ...

SELECT TOP 10 * FROM 表名 ORDER BY 排序字段

没有看到你的数据库conn连接啊: @$conn = mysql_connect("yourHost","yourUserID","yourPassword"); $sql=mysql_query("select top 3 title from art_title join art_neirong on art_title.no=art_neirong.no order by last_update DESC;",$conn...

网站首页 | 网站地图
All rights reserved Powered by www.dkfr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com