Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

order by month and year in sql

Posted on 2009-03-30
2
Medium Priority
?
2,526 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

963 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