Jump to content

get total in mysql query


otixz

Recommended Posts

Hi,

 

I need a msyql query that will calculate for the total of a given condition....

 

select sum(select amount from tblinquiries where inq_date = '22/04/2008') from tblinquiries

 

what I want to do is to get the TOTAL of all the amount of 22/4/2008 data from my tblinquiries table.

please help...what query can I use?

Link to comment
https://forums.phpfreaks.com/topic/103126-get-total-in-mysql-query/
Share on other sites

you could do it in php

 

$total = 0;
$query = "SELECT amount FROM tblinquiries WHERE inq_date = '22/04/2008'";
$result = mysql_query($query) or die ("Error in query " . mysql_error());
while ($row = mysql_fetch_assoc($result)
{
$total = $total + $row['amount'];
}
echo $total;

 

you could do it in php

 

$total = 0;
$query = "SELECT amount FROM tblinquiries WHERE inq_date = '22/04/2008'";
$result = mysql_query($query) or die ("Error in query " . mysql_error());
while ($row = mysql_fetch_assoc($result)
{
$total = $total + $row['amount'];
}
echo $total;

Why don't you show him mysql_num_rows?

 

The easiest way with MySQL is

SELECT COUNT(amount) as totalCount FROM tblinquiries WHERE inq_date = '22/04/2008';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.