calculating percentages php/mysql
Posted on 2012-09-17
I have three tables in MySQL - total sales, tuff sales, and float sales
tuff and float are types of sale.
Each table has columns year, month and sales.
The sum of sales for each type of sale = total. So for each month tuff sales + float sales = total sales.
I have a php query that reads the figures for each table in separate columns.
So if total sales for August 2012 were £120, and tuff sales = £100 and float = £20, then the php result would read:
2012 08 120 100 20
However is it possible for php to execute the SQL that presents the tuff and float sales as percentage of total?
So then the php result would read:
2012 08 120 83.3 16.7
I could write the percentage to the source table as a fixed calculation, and php would then read that column, but where is the fun in that?!