
How to get the sum of the column?
Moderator: General Moderators
How to get the sum of the column?
How to get the sum of the column, for example like in the photo?


Re: How to get the sum of the column?
When I learned Oracle's SQL there was a REPORT feature that allowed you to do what you want. However, in MySQL the only way that I know how is to run 2 separate queries. In your case it would be something like this:
Then do your usual HTML/PHP to bring'em together into a table.
Code: Select all
$query1 = "SELECT Muaji, Fitimi, Bortxh, Fitimi_Total from TABLE";
$query2 = "SELECT Sum(Fitimi_Total) from TABLE ";Re: How to get the sum of the column?
Assuming mysql and that you want the sum of last column only, you can do it in one query:
Code: Select all
select label, b, c, d, sum(b + c + d) from scratch group by label with rollupRe: How to get the sum of the column?
I think that there is a problem to do this, Because to show this data in the table, I use the above code. To be more clear, I have all the sales in a table in MySQL, then Here I collect all the sales from "November - 2009", "December 2009" etc... So Now I want to calculate all the sales of 2009, all the sales that are in the Table(in photo).manohoo wrote:When I learned Oracle's SQL there was a REPORT feature that allowed you to do what you want. However, in MySQL the only way that I know how is to run 2 separate queries. In your case it would be something like this:
Then do your usual HTML/PHP to bring'em together into a table.Code: Select all
$query1 = "SELECT Muaji, Fitimi, Bortxh, Fitimi_Total from TABLE"; $query2 = "SELECT Sum(Fitimi_Total) from TABLE ";
The Code:
Code: Select all
$sql = mysql_query("SELECT SUM(qtotal), SUM(borxh), DATE_FORMAT(data, '%m/%Y') AS dataere FROM riparimet GROUP BY dataere ORDER BY data DESC");Re: How to get the sum of the column?
*cough* Use WITH ROLLUP. http://dev.mysql.com/doc/refman/5.0/en/ ... fiers.html
Re: How to get the sum of the column?
just
don't go ???
Code: Select all
$sql = mysql_query("SELECT Sum(Fitimi_Total) from TABLE");
Re: How to get the sum of the column?
Thanks a lot for help, I made another query too, and did not group data in the other query. Because in the first query I grouped them.
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: How to get the sum of the column?
do one thing take the $Fitimi_Total value in loop and add like
before loop define $i=0;
inside the Loop $Fitimi_Tetal=$Fitimi_Tetal+$i;
and the Last just print Total $Fitimi_Tetal
before loop define $i=0;
inside the Loop $Fitimi_Tetal=$Fitimi_Tetal+$i;
and the Last just print Total $Fitimi_Tetal