Again, to continue with my mysql noob questions :) I want the following to be just one result:
select sum(sales_today) from table1
union
select sum(sales_yesterday) from table1
So right now that gives me two results, how do I make it give me only one, the summation of the two results? And how开发者_C百科 can I do to apply further equations to the result, such as dividing it by 2?
Thank you!
SELECT (SUM(sales_today) + SUM(sales_yesterday)) / 2 FROM table1
For more details on what you can use, see MySQL Functions and Operators.
You can add Expressions like you add fields. For easier access you should use the "AS"-keyword to give meaningful names:
select sum(sales_today) as TodaysSales,
sum(sales_yesterday) as YesterdaysSales,
((sum(sales_today) + sum(sales_yesterday)) / 2) as TwoDayAverage
from table1
精彩评论