troubleshooting Question

Create complex crosstab query with Oracle

Avatar of evotsi
evotsi asked on
Oracle Database
6 Comments1 Solution2163 ViewsLast Modified:
I have the attached query that produces the following results:
Year |  Month          |     MedianTime
2006      January        2
2006      October       3
2006      November       3
2006      December       1
2007      January       4
2007      February       2

What I need is this:
Month       | 2006Time | 2007Time
January    | 2              | 4
February  | 1              | 2
March       | 3              | 4

I used CASE on a simple query, however I can't get it to work on this one.  Also I am open to any suggestions to make this any simpler/better.
SELECT EXTRACT(YEAR FROM dateordered) "Year", TO_CHAR(TRUNC (dateordered, 'mm'), 'Month') "Month",
		ROUND(MEDIAN(dateshipped - dateordered),2) "MedianTime"
		FROM orders
		GROUP BY TRUNC (dateordered, 'mm'), EXTRACT(YEAR FROM dateordered)
		ORDER BY TRUNC (dateordered, 'mm'), EXTRACT(YEAR FROM dateordered)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros