Solved

order by month and year in sql

Posted on 2009-03-30
2
2,520 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

617 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