Hello, I have the following view for the 3rd quarter I need to add all 4 quarters in this view each in their respecitive columns. The only thing that will change is the qtr name (ie qt1, qtr2 etc) the sums and the date ranges, the % of target achieved will need to be at the end and calcuate all months. How can I join each of these queries for all quarters into one big one that will output each quarter in the view, ive tried using the UNION statement but get the final output in one column as seen below instaed of an additional column? - let me know your thoughts or suggestion. - thanks
SQL> SELECT campus.campus,
2 ROUND(campus.QTR3/tot_contr,2)*q3 "QTR3"
3 FROM campus,(SELECT SUM(AMOUNT) Q3
4 FROM contribution wHERE CDATE >= TO_DATE('07/01/03', 'MM/DD/YY')
5 AND CDATE <= TO_DATE('09/30/03', 'MM/DD/YY')),
6 (SELECT SUM(QTR3) Tot_Contr FROM campus)
7 UNION ALL
8 SELECT campus.campus,
9 ROUND(campus.QTR2/tot_contr,2)*q2 "QTR2"
10 FROM campus,(SELECT SUM(AMOUNT) Q2
11 FROM contribution wHERE CDATE >= TO_DATE('04/01/03', 'MM/DD/YY')
12 AND CDATE <= TO_DATE('06/30/03', 'MM/DD/YY')),
13 (SELECT SUM(QTR2) Tot_Contr FROM campus);
CAMPUS QTR3
------ ----------
Main 396.9
East 194.4
West 97.2
North 121.5
Main 380.7
East 234.9
West 97.2
North 97.2
SQL> SELECT campus.campus,
2 ROUND(campus.QTR3/tot_contr,2)*q3 "QTR3"
3 FROM campus,(SELECT SUM(AMOUNT) Q3
4 FROM contribution wHERE CDATE >= TO_DATE('07/01/03', 'MM/DD/YY')
5 AND CDATE <= TO_DATE('09/30/03', 'MM/DD/YY')),
6 (SELECT SUM(QTR3) Tot_Contr FROM campus)
7 UNION ALL
8 SELECT campus.campus,
9 ROUND(campus.QTR2/tot_contr,2)*q2 "QTR2"
10 FROM campus,(SELECT SUM(AMOUNT) Q2
11 FROM contribution wHERE CDATE >= TO_DATE('04/01/03', 'MM/DD/YY')
12 AND CDATE <= TO_DATE('06/30/03', 'MM/DD/YY')),
13 (SELECT SUM(QTR2) Tot_Contr FROM campus);
CAMPUS QTR3
------ ----------
Main 396.9
East 194.4
West 97.2
North 121.5
Main 380.7
East 234.9
West 97.2
North 97.2