Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNION STATEMENT MULTIPLE COLUMNS

Status
Not open for further replies.

eggohead

Technical User
Oct 19, 2003
25
US
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 &quot;QTR2&quot;
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
 
Eggohead,

I cannot find the other recent thread that I'm looking for. The reason I cannot find it may be because someone may have clicked the thread as &quot;Inappropriate...&quot; since they deduced that it was a classroom assignment (and somehow that possibility made it past me). Since the description of your VIEW is just about identical to the post I cannot find from another posting person for whom I resolved this issue within the last couple of days, I must withhold my participation from a resolution (and recommend others defer, as well), unless there is some proof this is not for a classroom-type assignment.

Dave
Sandy, Utah, USA @ 00:39 GMT, 17:39 Mountain Time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top