Restructure a Query

LadyDi

Registered User.
Local time
Today, 12:55
Joined
Mar 29, 2007
Messages
894
I have a union query in my database that calculates the average hours it takes to install equipment for various customers. Right now, it lists everything down, like this:
Customer Type ------ Average Install Hours ---- Install Month --- Install Year
Strategic ------------ 4.5 ---------------------- 4 ---------------2013
Strategic ------------ 4.2 ---------------------- 3 ---------------2013
Strategic ------------ 3.6 ---------------------- 2 ---------------2013
Regional ------------- 2.5 ---------------------- 4 ---------------2013

and so forth.
I would like to take these results and restructure them, but I'm not sure how to do that. I want my results to look like this:

Install Month ----- Install Year ----- Strategic ----- Regional
4 ------------------ 2013 ----------- 4.5 ----------- 2.5
3 ------------------ 2013 ----------- 4.2 ----------- 2.0
2 ------------------ 2013 ----------- 3.6 ----------- 1.5

Is this possible? Any assistance you can provide would be greatly appreciated.
 
try using a crosstab query.

  1. Set the Install Year amd month to row headings/group by
  2. Set the Customer Type to Column heading/group by
  3. Set the Average Install Hours to Value/sum
  4. right click on the query window and display properties (if not already visible)
  5. Set the row headings to "Strategic","Regional" (controls the column order and enables the query to be displayed on a form or report)
 
That worked, a little slow, but it worked. Thank you very much.
 
If it is a bit slow, there are some things you can do which should speed it up

ensure the year, month and customer type fields are indexed
consider combining year and month into one field (201303 for March 2013)

But the biggest thing to slow it down is the union query - can be slow for large amounts of data.

So can your data be restructured to avoid a union query?
Alternatively change your union query to update a temporary table and base your crosstab on that
 

Users who are viewing this thread

Back
Top Bottom