MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

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
  #1  
Old July 28th, 1999, 06:44 AM
Herring
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:

Hi,

I need to multiply two columns in a query and then add the results together
based on an id.

I`ve already made a query:

select lc.location,
fc.name,
fd.sweight*lc.lweight as score
from funcdef fd
left join
loccri lc on fd.criteria=lc.criteria
left join
locations loc on loc.ID=lc.location
where
function=1 and lc.criteria!=null

here`s the result:

location name score
5 market place 500
4 post office 3750
2 railwaystation 1000
2 railwaystation 1000
2 railwaystation 2000
2 railwaystation 2000
5 market place 1500
2 railwaystation 1500
2 railwaystation 1500
5 market place 3000

now I would need to get the cumulative results of each location. as in

loc score
5 5000
2 9000
4 3750

i`ve done this in php, but i`d like to use sql queries since the table
can grow to thousends of rows, and optimizing queries seems like a good
idea.
I don`t know how to do the second query.
is there a way to do all of this in one query, or do I need to use temporary tables?

- matti

Reply With Quote
  #2  
Old July 28th, 1999, 07:47 PM
DesertFox
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Matti,

This might spark some ideas.

In an old dos database I use, I can issue this select command:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
SELECT COL1, SUM(COL2 * COL3) FROM TABLE1 GROUP BY COL1 WHERE ....(Whatever)
[/quote]

I haven't looked at the select syntax in the MySQL document when I posted this message. Maybe it might require some tweaking.

Hope this helps.

DesertFox

Reply With Quote
  #3  
Old July 29th, 1999, 03:13 AM
Herring
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks, I got it working with this query...
someone said that doing left joins is not very efficient... I'll do some optimizing on the query later, just had to get it working first.

select
lc.location
, loc.name
, sum(fd.sweight*lc.lweight) as score
from
funcdef fd
left join loccri lc on fd.criteria=lc.criteria

left join locations loc on loc.ID=lc.location

where
fd.function=(1 or 2)
and lc.criteria!='null'
group by
lc.location
order by
score desc

- Herring

Reply With Quote
  #4  
Old July 29th, 1999, 03:16 AM
Herring
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
fd.function=(1 or 2) is a typ0 and notin the actual query : fd.function=1, sorry
- Herring

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > multiple queries and math???


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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