Roy Harper
Coder
I created a view for weekly sales. Everything is working fine on localhost using MySQL.
But when I upload the database on GoDaddy Lag doesn't seem to work.
When I am typing LAG on phpmyadmin, no suggestion is showing. Can anyone help me with this one? Thanks
the structure of vw_sales is
+-----------+------+
| order_date| sales |
+-----------+------+
Here's my code:
But when I upload the database on GoDaddy Lag doesn't seem to work.
When I am typing LAG on phpmyadmin, no suggestion is showing. Can anyone help me with this one? Thanks
the structure of vw_sales is
+-----------+------+
| order_date| sales |
+-----------+------+
Here's my code:
SQL:
CREATE VIEW vw_weekly_sales AS
SELECT
YEAR(order_date) AS YEAR,
WEEK(order_date) AS WEEK,
SUM(sales) AS sales,
SUM(sales) - LAG(sales) OVER (ORDER BY vw_sales.`order_date` ASC) AS sales_growth,
(SUM(sales) - LAG(vw_sales.`sales`) OVER (ORDER BY vw_sales.`order_date` ASC)) / LAG(sales) OVER(ORDER BY vw_sales.`order_date` ASC) * 100 AS sales_growth_percentage
FROM vw_sales
GROUP BY YEAR(order_date), MONTH(order_date), WEEK(order_date);