Oracle:如何对查询进行排序以按正确顺序获得月份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6364871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle: How to sort the query to get months in proper sequence
提问by Rachel
I am working on an report for which am calling a function from front end. I am getting start month information as numbers starting from 1 to 12 and so am using
我正在编写一份报告,该报告正在从前端调用一个函数。我得到的开始月份信息是从 1 到 12 的数字,所以我正在使用
substr(to_date(START_MONTH,'MM'),4,3)
to get month in the form of Jan, Feb etc, now in my function am grouping by start month and then ordering by start month and so in the output am getting values like
以 Jan、Feb 等形式获取月份,现在在我的函数中按开始月份分组,然后按开始月份排序,因此在输出中我得到的值如下
Apr, Aug, Dec as it is ordering by First alphabet of the month, how can I get correct order starting from Jan to Dec?
4 月、8 月、12 月,因为它按本月的第一个字母排序,我如何才能从 1 月到 12 月获得正确的顺序?
Any suggestions?
有什么建议?
Also how to sort number so that 2 comes after 1 and not 10 after 1?
另外如何对数字进行排序,使 2 在 1 之后而不是 10 在 1 之后?
回答by Randy
order by to_date( start_month, 'mm' )
按 to_date ( start_month, 'mm' ) 排序
?
?