Complex Query Question

G

Gary

I have created a crosstab query that will give me the number of
occurrences of certain types (1-5) over a given period of months. I
am using VB to create a listing of the months as I don't want missing
columns if there are no occurences. What I would then like to do is
create a weighted index number based on the data and use it in a
multiple type chart.
I have the weighted index in another query but in rows instead of
columns and it will skip months if there is no data..

How can I combine the two queries to give me an output suitable for a
chart? (ie add row with weighted index at bottom)

Any suggestions appreciated.
Gary

Query 1: SQL
TRANSFORM Count(Q_MASTER.ID) AS CountOfID
SELECT Q_MASTER.incident_severity
FROM Q_MASTER
GROUP BY Q_MASTER.incident_severity
ORDER BY Q_MASTER.incident_severity, (Format([Date],"mmm"" '""yy"))
DESC
PIVOT (Format([Date],"mmm"" '""yy")) In ("Jan '06","Feb '06","Mar
'06","Apr '06","May '06","Jun '06","Jul '06","Aug '06","Sep '06","Oct
'06","Nov '06","Dec '06","Jan '07","Feb '07","Mar '07","Apr '07","May
'07","Jun '07");

Query1 output:
incident_severity Jan '06 Feb '06 Mar '06 Apr '06 May '06 Jun '06
2 6 4 2 1 3 9
3 2 2 2 5 2
4 1 4 2 1
5


Query 2: SQL
TRANSFORM Count(Q_MASTER.ID) AS CountOfID
SELECT (Format([Date],"mmm"" '""yy")) AS dates,
IIf(Sum(IIf([incident_severity]>2,[incident_severity],
0))>0,Sum(IIf([incident_severity]>2,[incident_severity],0))/
Sum(IIf([incident_severity]>2,1,0)),0) AS [Avg of Serious]
FROM Q_MASTER
WHERE (((Q_MASTER.incident_severity)>1))
GROUP BY (Year([Date])*12+Month([Date])-1), (Format([Date],"mmm""
'""yy"))
PIVOT Q_MASTER.incident_severity;

Query2: output
dates Avg of Serious 2 3 4 5
Jan '06 3.33 2 1
Feb '06 3 4 2
Mar '06 4 2 4
Apr '06 3.5 1 2 2
May '06 3.166 3 5 1
Jun '06 3 9 2

What I am trying to get is an output similiar to Query 1 but with an
additional row with the formula output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top