MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 28th, 2003, 07:44 PM
aussiesonofagun aussiesonofagun is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Cairns Australia
Posts: 17 aussiesonofagun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SUM array

Hi Guys,

below is a simple SQL query designed to extract a total from a single table.

What I have been trying to do is take these two sums and add them together giving a result.

Can anyone help me with the correct way to do this, no matter what I have tried I can't seem to get anywhere with it.

I am not sure whether I exctract these two totals then add them together or whether there is a way to change my code to so that it adds up the columns from the two tables then displays a result with both figures added together. The only catch is that it is conditional (ie. SELECT SUM(total) AS total_price1 FROM detail_tourdet WHERE voucher_id = '$voucher_id'"
FYI - voucher ID is a parameter passed from a previous page.


Best Regards
Steve


<?php $sql = "SELECT SUM(total) AS total_price1 FROM detail_tourdet WHERE voucher_id = '$voucher_id'";
$result = mysql_query ( $sql );
$row=mysql_fetch_array($result);
echo $row['total_price1']; ?>


<?php $sql = "SELECT SUM(total) AS total_price2 FROM retail_acom WHERE voucher_id = '$voucher_id'";
$result = mysql_query ( $sql );
$row=mysql_fetch_array($result);
echo $row['total_price2']; ?>

Reply With Quote
  #2  
Old October 29th, 2003, 03:19 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Code:
select sum(total) AS total_price1
from (select total  
FROM detail_tourdet 
WHERE voucher_id = '$voucher_id'
union all 
SELECT total 
FROM retail_acom 
WHERE voucher_id = '$voucher_id') dt

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SUM array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway