Solved

order by month and year in sql

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now