Solved

order by month and year in sql

Posted on 2009-03-30
2
2,509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
setting local variables in a cursor block 3 29
SQL Recursion schedule 13 34
Syntax error creating JSON recordset 4 26
SP result not being displayed 5 39
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

756 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