order by 奇特排序技巧
来源:互联网 发布:windows 触摸板 增强 编辑:程序博客网 时间:2024/04/20 14:27
網上看到了幾個 用order by 實現的特殊排序規則,感覺以後可能會用上,特記錄之,整理了一下,直接上代碼算了:
if object_id('tempdb..#temp') is not nulldrop table #tempcreate table #temp(col1 varchar(100), col2 varchar(100))insert into #tempselect 'X68.23','4'union all select 'X86.32','2'union all select 'ZA11.30','1'union all select 'ZB11.47','1'go------ 需求一、按col 4,1,2排序-- 用 charindexselect col1,col2 from #temporder by charindex(col2,'4,1,2')-- order by 中用 caseselect col1,col2 from #temporder by case col2when '4' then 1when '1' then 2when '2' then 3else 3 + rand()end-- 用 unionselect col1,col2 from #temp where col2 = '4' union allselect col1,col2 from #temp where col2 = '1' union allselect col1,col2 from #temp where col2 = '2'------ 需求二、 col 4 排第一,其余随便select col1,col2 from #temporder by case col1when '4' then 1else 1 + rand()end------ 需求三、 随机排序select col1,col2 from #temporder by newid()
- order by 奇特排序技巧
- order by 使用技巧
- Mysql Order By 技巧
- order by 排序
- order by 自定义排序
- ORDER BY排序查询
- mysql order by注入技巧
- SQL查询排序ORDER BY
- oracle order by排序总结
- 数据的排序:(order by)
- ORACLE ORDER BY 排序规则
- SQL 经典排序 Order By
- MySQL排序:SELECT ORDER BY
- linq 动态排序 order by
- SQL ORDER BY不规则排序
- oracle order by 拼音排序
- mysql order by内排序
- mysql排序order by新发现
- Java重写equals时应注意的问题汇总
- 基础知识——多线程
- 技术思考
- 安卓:Activity:Tasks and Back Stack
- IM example
- order by 奇特排序技巧
- Apache下.htaccess文件常用配置
- curl可以在shell下轻松上传下载ftp
- Linux 对象存储文件系统的研究
- 手记一
- 如何把java项目发布到Web容器(Tomcat)中
- vpn
- HTTP错误405-Method Not Allowed
- VC程序员常用工具