|
Hey Reader -- I'm trying something new this week! Can you take a minute to fill out this quick survey? Thanks in advance!
Okay, on to this weeks topic: Imagine this: Your boss walks into the Monday morning meeting and says "Show me revenue trends for the last 6 months." Everyone looks at you. Most analysts panic. They open Excel, export CSVs, build pivot tables, make charts. An hour later, they have numbers but no story. Confident analysts? They write one SQL query and present insights in minutes with full confidents. Here's how: The Query That Executives LoveI just ran this against the live Summit Adventures database (the fake adventure tourism company I created to help people learn business analytics):
Here's what we found for Summit Adventures (limited to 6 months of data to show the concept. In the real world, you'd run all 12 months...):
The story these numbers tell: Summit Adventures had a strong summer season (June-August: over $464K revenue, 260 bookings) but revenue dropped 90% from June to November. Think of this as a strategic conversation starter:
One query. Three executive-ready insights. That's what confident analysts deliver. Breaking Down The QueryLine 3: TO_CHAR() for month formatting Converts timestamps to 'YYYY-MM' format (2025-06) so we can group by month. Without this, you'd group by exact payment time which isn't useful for trends. Lines 4-6: Three key metrics
All three together tell a complete story. Line 10: The 12-month rolling window Line 11: GROUP BY matches Line 3 Important rule: Your GROUP BY must match your SELECT for non-aggregated columns. Same TO_CHAR() format on both. Why This Simple Query Works At Any CompanyThis pattern adapts to any business: E-commerce → GROUP BY TO_CHAR(order_date, 'YYYY-MM') SaaS → GROUP BY TO_CHAR(subscription_start_date, 'YYYY-MM') Retail → GROUP BY TO_CHAR(transaction_date, 'YYYY-MM') The structure stays the same. Just change the table names and date column. Common Mistakes to AvoidMistake #1: Not filtering payment_status If you include pending or failed payments, your revenue numbers are fantasy. Always filter for 'completed' or 'succeeded' status. Mistake #2: Using date ranges instead of intervals
Mistake #3: Not ordering by month If you don't ORDER BY the month column, results come back random. This look chaotic and messy. Try This TomorrowOpen your company database. Run this pattern:
Replace:
You'll have executive-ready revenue trends in under a minute. What Executives Actually Want to SeeThey don't want raw data dumps. They really want answers:
This one query delivers all three. The next time someone asks for "revenue trends," you'll be the analyst who delivers insights, not just numbers. Until next time, Brian P.S. Are you interested in more SQL content or something else like Python, Tableau, or Agentic AI? Let me know in this 2 minute survey when you get this email. |
Learn to build analytics projects with SQL, Tableau, Excel, and Python. For data analysts looking to level up their career and complete beginners looking to get started. No fluff. No theory. Just step-by-step tutorials anyone can follow.
Hey Reader, Imagine you're a marketing analyst and your marketing director walks over and says: "I need our customers broken into spending tiers (VIP, Standard, and Low Value) so I can send different emails to each group." You have the data. But every customer just has a dollar amount. There's no "tier" column in the database. How do you create categories that don't exist yet? This is where CASE WHEN becomes one of the most useful tools in your SQL toolkit. The problem is that raw data...
Hey Reader, This week's newsletter is different. Not a regular "how to solve problem X with SQL" kinda thing. Because I've realized something: you can write perfect queries and still never get the career impact you want. You need "soft skills" like presenting your results to leadership in addition to "technical skills" like using CTEs and WINDOW functions. Let me show you what I mean. The Scenario Wednesday, 2pm. Q2 review meeting. CMO: "Our booking conversion is down. What's causing it?"...
Hello Reader, Imagine this scenario: Your CMO walks into Monday's meeting with a question: "I need to see our top 3 highest-revenue expeditions in EACH category - hiking, climbing, safari, cultural, and photography." Most analysts would write 5 separate queries, one per category. Or export to Excel and manually filter. An hour of work, minimum. Confident analysts write one query using window functions. Takes 3 minutes. Here's the skill that separates intermediate analysts from advanced ones....