Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

adding SUM to query
I have a SELECT * query that returns info such as 'name', 'date',
'cost', and 'notes'.  At the head of this query return it reads how
many records were found.  I would like to append that with 'how many
records were found at a cost of' ...

But haven't been able to find a means of totalizing the 'cost' column
in my query.  Does anyone have any ideas on how this might be
accomplished ???  I've spent considerable time on the net looking at
examples and my reference book but so far, no luck.

TIA,
Chris

Report this thread to moderator Post Follow-up to this message
Old Post
Chris
05-28-05 08:56 PM


Re: adding SUM to query
Chris (coverland914@yahoo.com) wrote:
: I have a SELECT * query that returns info such as 'name', 'date',
: 'cost', and 'notes'.  At the head of this query return it reads how
: many records were found.  I would like to append that with 'how many
: records were found at a cost of' ...

: But haven't been able to find a means of totalizing the 'cost' column
: in my query.  Does anyone have any ideas on how this might be
: accomplished ???  I've spent considerable time on the net looking at
: examples and my reference book but so far, no luck.

The row count you see is extra information, it is not part of the query,
and what sort of information you can get depends on the application you
are using.  Something like mysql will give you basic feedback such as the
row count.  If you used a report application then you could ask the report
application to provide a sum at the end, but otherwise you have to
calculate it your self.  If you used a report application then it would
simply be doing something like what I describe below.


There are two basic ways to do it your self

-1- do the sum yourself as you scan through the rows
(pseudo code, based on some mysql/php examples I have)

$sum = 0;
while($row = mysql_fetch_array($sth))
{
$sum += $row[cost];
Print_the_row($row);
}
Print_the_cost($sum);


-2- or use two queries


mysql> select * from query;
mysql> select sum(cost) from query;



--

This space not for rent.

Report this thread to moderator Post Follow-up to this message
Old Post
Malcolm Dew-Jones
05-29-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:37 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.