Prompt Details
Model
Chat GTP 4
Example input
[Data__Request]: Calculate the monthly revenue growth rate for the 'orders' table for the year 2023.
Example output
-- Calculate Monthly Revenue and Growth Rate
WITH MonthlyRevenue AS (
SELECT
DATE_FORMAT(order_date, '%Y-%m') AS month,
SUM(total_amount) AS revenue
FROM orders
WHERE YEAR(order_date) = 2023
GROUP BY 1
)
SELECT
month,
revenue,
LAG(revenue) OVER (ORDER BY month) AS previous_month_revenue,
(revenue - LAG(revenue) OVER (ORDER BY month)) / LAG(revenue) OVER (ORDER BY month) * 100 AS growth_rate_percent
FROM MonthlyRevenue; Preview Output Generated by This Prompt
Tags and categories