How can i calculate and show the percentage of growth or loss, on the previous month (comparing the figure from the previous month, not previous year).
i.e. Jan is 500, so results will be 0%. Then as Feb is 150, the percentage loss is -70%, March will show -86.67 as their results were only 20 (compared to Febs 150)
+----------+------+------------+
| Month | Sale | Difference |
+----------+------+------------|
| January | 500 | |
| February | 150 | -70.00 |
| March | 20 | -86.67 |
| April | 250 | 1150.00 |
| May | 280 | 12.00 |
| June | 400 | 42.86 |
| July | 480 | 20.00 |
+----------+------+------------+
My script below produces: (I just need to add another percentage column
+----------+-------------------+
| MONTH | SUM(SALES_AMOUNT) |
+----------+-------------------+
| January | 500 |
| February | 150 |
| March | 20 |
| April | 250 |
| May | 280 |
| June | 400 |
| July | 480 |
+----------+-------------------+
SELECT coalesce(date_format(DATE_PURCHASED, '%M')) AS MONTH,
SUM(SALE_PRICE)
FROM SALE
WHERE YEAR(DATE_PURCHASED) = 2017
GROUP BY month
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…