Home » Fusion Middleware & Colab Suite » Business Intelligence » Case Statement Month Rank
|
Re: Case Statement Month Rank [message #639320 is a reply to message #639318] |
Mon, 06 July 2015 04:10 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
I don't use OBIEE, but - generally speaking - you are looking for a correct ORDER BY clause. Here's an example, see if you can adjust it accordingly to your needs.
I'm selecting employees from Scott's EMP table, displaying different HIREDATE column values, as returned by different TO_CHAR function parameters (i.e. format masks).
- HIRE_MM - two characters, but numeric representation of a month
- HIRE_MONTH_CRO - month name in my default language (Croatian)
- HIRE_MONTH_ENG - month name in English
I prefer using numbers than characters because NLS settings might change, and query - which was working just fine - suddenly returns incorrect results. That's why I used 'MM' format mask in my ORDER BY clause.
As I said: have a look, pick an option you find the most suitable (if any).
SQL> SELECT ename,
2 TO_CHAR (hiredate, 'dd.mm.yyyy') hire_date,
3 TO_CHAR (hiredate, 'mm') hire_mm,
4 TO_CHAR (hiredate, 'month') hire_month_cro,
5 TO_CHAR (hiredate, 'month', 'nls_date_language = english')
6 hire_month_eng
7 FROM emp
8 ORDER BY CASE
9 WHEN TO_CHAR (hiredate, 'mm') = '04' THEN 1
10 WHEN TO_CHAR (hiredate, 'mm') = '05' THEN 2
11 WHEN TO_CHAR (hiredate, 'mm') = '06' THEN 3
12 WHEN TO_CHAR (hiredate, 'mm') = '07' THEN 4
13 WHEN TO_CHAR (hiredate, 'mm') = '08' THEN 5
14 WHEN TO_CHAR (hiredate, 'mm') = '09' THEN 6
15 WHEN TO_CHAR (hiredate, 'mm') = '10' THEN 7
16 WHEN TO_CHAR (hiredate, 'mm') = '11' THEN 8
17 WHEN TO_CHAR (hiredate, 'mm') = '12' THEN 9
18 WHEN TO_CHAR (hiredate, 'mm') = '01' THEN 10
19 WHEN TO_CHAR (hiredate, 'mm') = '02' THEN 11
20 WHEN TO_CHAR (hiredate, 'mm') = '03' THEN 12
21 END;
ENAME HIRE_DATE HI HIRE_MON HIRE_MONT
---------- ---------- -- -------- ---------
JONES 02.04.1981 04 travanj april
BLAKE 01.05.1981 05 svibanj may
CLARK 09.06.1981 06 lipanj june
TURNER 08.09.1981 09 rujan september
MARTIN 28.09.1981 09 rujan september
KING 17.11.1981 11 studeni november
MILLER 23.12.1982 12 prosinac december
SCOTT 09.12.1982 12 prosinac december
JAMES 03.12.1981 12 prosinac december
FORD 03.12.1981 12 prosinac december
SMITH 17.12.1980 12 prosinac december
ADAMS 12.01.1983 01 siječanj january
WARD 22.02.1981 02 veljača february
ALLEN 20.02.1981 02 veljača february
14 rows selected.
SQL>
[Updated on: Mon, 06 July 2015 04:11] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat Jan 04 17:11:07 CST 2025
|