[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql
Subject:    RE: summing values
From:       "Mazur Worden, Kathy" <kathymw () palsnet ! info>
Date:       2006-06-30 15:57:12
Message-ID: 384D1CF49B99B44AA1D51B1246FE51A198E6F7 () swponyexpress ! prairie ! local
[Download RAW message or body]

Here's a sample of some votes in the table:

SectionA Nominee1	SectionA Nominee2
--------------------------------------------
Cynthia Smith	n/a
Maggie Doe		n/a
Maggie Doe		Cynthia Smith
Maggie Doe		Cynthia Smith
Maggie Doe		Cynthia Smith
Maggie Doe		Cynthia Smith
Maggie Doe		Cynthia Smith
Maggie Doe		Sally Brown
Maggie Doe		Cynthia Smith
Maggie Doe		n/a

I want a result that looks like this:

Section A		Number of Votes
--------------------------------------------
Maggie Doe		9
Cynthia Smith	8
Sally Brown		1

"Number of votes" needs to sum up the number of votes for one person from both columns.

Does that help?

Kathy Mazur Worden
Prairie Area Library System
________________________________________
From: Peter Brawley [mailto:peter.brawley@earthlink.net] 
Sent: Friday, June 30, 2006 10:45 AM
To: Mazur Worden, Kathy
Cc: mysql@lists.mysql.com
Subject: Re: summing values

>Since one person can be listed in both 1 and 2 in each section (just not
>in the same row) I need to sum up that person's votes between the two
>columns.  I've tried summing two subqueries but it errors out because of
>returning two values.  

Unclear. Where is a user's 1 or 2 recorded? What is a "sum .. between two columns"?

PB

-----

Mazur Worden, Kathy wrote: 
I'd like to sum up values from two different columns in one table that
is constructed like this:

 

CREATE TABLE `nominations`

 ( `id` smallint(5) unsigned NOT NULL auto_increment, 

`name` varchar(255) default NULL, 

`SectionA_Nominee1` varchar(255) NOT NULL default 'n/a', 

`SectionA_Nominee2` varchar(255) NOT NULL default 'n/a', 

`SectionB_Nominee1` varchar(255) NOT NULL default 'n/a',

 `SectionB_nominee2` varchar(255) NOT NULL default 'n/a'

`submittedwhen` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP, `submittedfrom` varchar(50) NOT NULL default
'unavailable', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1

 

The table has a row added each time a vote is cast.  For each section
one or two votes can be placed from a list of 4 nominees.

 

Since one person can be listed in both 1 and 2 in each section (just not
in the same row) I need to sum up that person's votes between the two
columns.  I've tried summing two subqueries but it errors out because of
returning two values.  

 

Any other ways to accomplish this?

 

Kathy Mazur Worden

Prairie Area Library System

 


  

________________________________________

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.8/380 - Release Date: 6/30/2006
  

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@progressive-comp.com


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic