Solved

order by month and year in sql

Posted on 2009-03-30
2
2,504 Views
Last Modified: 2013-12-07
hi,

i am using below query

SELECT DISTINCT Month(STMTR_D) as stmMonth, Year(STMTR_D) as stmYear
FROM STMTR where STMTR_AN = '12345'
and STMTR_BI = '01' order by Month(STMTR_D) asc,Year(STMTR_D) asc

which gives me as output

stmMonth  stmYear
1        2009
2        2009
10        2008
11        2008
12        2008

how must i change the query in order to get the output like:

stmMonth  stmYear
2        2009
1        2009
12        2008
11        2008
10        2008
0
Comment
Question by:eaweb
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24022058
you want this:
SELECT DISTINCT Month(STMTR_D) as stmMonth, Year(STMTR_D) as stmYear 
FROM STMTR where STMTR_AN = '12345' 
and STMTR_BI = '01' 
order by Year(STMTR_D) desc, Month(STMTR_D) desc

Open in new window

0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24022085
Try out this query:

SELECT DISTINCT Month(STMTR_D) as stmMonth, Year(STMTR_D) as stmYear
FROM STMTR
where STMTR_AN = '12345'
and STMTR_BI = '01'
order by Year(STMTR_D) desc, Month(STMTR_D) desc

This will do
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question