I have the following two queries:
SELECT applicationid as LastMonthID, month(sold) AS LastMonthSold, SUM(quantity) AS LastMonthTotalSales
FROM(
SELECT applicationid, sold, quantity
FROM Sales
JOIN WebApplication
ON applicationid = id) AS AllMonthlySales
WHERE month(sold) = month(now())-1
GROUP BY applicationid;
SELECT applicationid ThisMonthID, month(sold) AS ThisMonthSold, SUM(quantity) AS ThisMonthTotalSales
FROM (
SELECT applicationid, sold, quantity
FROM Sales
JOIN WebApplication
ON applicationid = id) As AllMonthlySales
WHERE month(sold) = MONTH(now())
GROUP BY applicationid;
These queries produce the following:
- applicationid
- the month (number) for which the sale happened
- The sum of the quantity sold for EACH application
I would like to do the following:
- Compare last month's quantity, to this month's quantity for EACH application. If there is a 5% DECREASE in the quantity sold, it should give me the applicationid for THAT specific application. How would I accomplish this?