Write a SQL query to retrieve the revenue for the previous year.
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
Assuming a table sales with columns sale_date (DATE) and revenue (DECIMAL), you can get the previous calendar year’s revenue with:
sql
SELECT SUM(revenue) AS total_revenue
FROM sales
WHERE YEAR(sale_date) = YEAR(CURRENT_DATE) - 1;If you need the previous fiscal year or a rolling 12‑month period, adjust the date logic accordingly:
sql
-- Rolling 12 months
SELECT SUM(revenue) AS total_revenue
FROM sales
WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH)
AND sale_date < CURRENT_DATE;Both queries run in O(n) time over the rows that satisfy the WHERE clause, and the index on sale_date (if present) will make the filtering efficient.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500