码迷,mamicode.com
首页 > 数据库 > 详细

SQL排序包含数字、字母和中文处理

时间:2019-08-22 16:07:28      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:rom   sql   cas   order   int   sele   --   包含   char   

--模拟数据

SELECT * INTO #temp FROM
(
  SELECT 1 AS id, ‘C101‘ AS sort
  UNION ALL
  SELECT 2 AS id, ‘B101‘ AS sort
  UNION ALL
  SELECT 3 AS id, ‘101‘
  UNION ALL
  SELECT 4 AS id, ‘1101‘
  UNION ALL
  SELECT 5 AS id, ‘201‘
  UNION ALL
  SELECT 6 AS id, ‘风‘
  UNION ALL
  SELECT 7 AS id, ‘花‘
  UNION ALL
  SELECT 8 AS id, ‘雪‘
  UNION ALL
  SELECT 9 AS id, ‘月‘
) S

--查询排序

SELECT * FROM #temp ORDER BY RIGHT(REPLICATE(‘0‘,10)+CAST(sort AS VARCHAR(10)),10) ASC

SQL排序包含数字、字母和中文处理

标签:rom   sql   cas   order   int   sele   --   包含   char   

原文地址:https://www.cnblogs.com/xy0710/p/11394759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!