php - Mysql Query SUM dynamic amounts -
i need writing mysql query sum amounts in column columns values may different depending on value contains. here example of table.
account type amount ------- ---- ------ dell inventory 500.00 microsoft inventory 100.00 cisco inventory 300.00 dell inventory 400.00 webhosting service 15.00
here have far, not can't think of way this.
$result = mysql_query("select * table type = 'inventory'"); while($row = mysql_fetch_array($result)){ sum amounts each account type. account types not fixed, change regularly }
as note above says, account fields not fixed cannot hard code queries names of account.
then have report detailing totals of each account.
dell $900 microsoft $100 cisco $300
thanks help!
you need use aggregate function sum()
total amount every account.
select account, sum(amount) totalamount tablename type = 'inventory' group account
Comments
Post a Comment