Day 36 – Date Functions On my first day as a data analyst, my manager asked: "Can you show me all orders from the last 30 days?" I wrote: WHERE order_date = '2024-03-16' and manually counted back. Every day I had to update it. Every weekend it broke. Then I learned: WHERE order_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) That one line is self-updating. Run it today, tomorrow, next year always shows last 30 days. Date functions are in 90% of real SQL queries. Here are the ones that matter most: Get today: CURDATE() → 2024-04-15. NOW() → includes time. Extract parts: YEAR(date), MONTH(date), DAY(date) → use for GROUP BY month Calculate gaps: DATEDIFF(date1, date2) → days between. TIMESTAMPDIFF(MONTH, d1, d2) → months/years Shift dates: DATE_ADD(date, INTERVAL 30 DAY) → 30 days later. DATE_SUB → go back Format output: DATE_FORMAT(date, '%Y-%m') → 2024-04. Use '%Y-%m' for monthly grouping (year first = sorts correctly!) Day 36 / 60 — SQL for Beginners. Follow for a new concept every day. 🚀 #SQL #LearnSQL #SQLforBeginners #DataAnalytics #TechCareer #DataScience
SQL Date Functions for Data Analysis
More Relevant Posts
-
🚀 Day 12 – Data Analyst Journey Today I focused on advanced SQL querying techniques, especially combining data from multiple tables and performing analytical operations. 🗄️ SQL Concepts Covered: 🔗 SQL Joins: - INNER JOIN – returns matching records from both tables - LEFT JOIN – returns all records from left table + matched from right - RIGHT JOIN – returns all records from right table + matched from left 📊 Window Functions (Advanced SQL 🔥): Learned how to perform calculations across a set of rows without grouping them. 📌 Types of Window Functions: 1️⃣ Ranking Functions: - "ROW_NUMBER()" - "RANK()" - "DENSE_RANK()" 2️⃣ Aggregate Window Functions: - "SUM()" - "AVG()" - "COUNT()" - "MIN()" - "MAX()" 3️⃣ Value Functions: - "LAG()" - "LEAD()" - "FIRST_VALUE()" - "LAST_VALUE()" 4️⃣ Distribution Functions: - "NTILE()" 💡 Also understood how to use "OVER()" clause with "PARTITION BY" and "ORDER BY" to control window behavior. 💡 Today’s learning helped me analyze data at a deeper level without losing row-level details — a key skill for real-world data analysis. #SQL #DataAnalytics #WindowFunctions #LearningJourney #FutureDataAnalyst #PlacementPrep
To view or add a comment, sign in
-
There are over 600 SQL functions. Here are 22 that you must know by heart as a data analyst. 1. SELECT - Extract specific data. 2. WHERE - Filter rows based on conditions. 3. DISTINCT - Remove duplicate values. 4. ORDER BY - Sort results. 5. LIMIT / TOP - Return a set number of rows. 6. COUNT) - Count rows. 7. SUM() - Add up values. 8. AVG(- Calculate average. 9. MIN( - Find the lowest value. 10. MAX - Find the highest value. 11. GROUP BY - Aggregate data by categories. 12. HAVING - Filter groups after aggregation. 13. INNER JOIN - Return matching records. 14. LEFT JOIN - Return all from left + matches. 15. RIGHT JOIN - Return all from right + matches. 16. FULL JOIN - Return all from both tables. 17. CASE WHEN - The "If/ Then" of SQL. 18. COALESCE) - Handling those annoying NULLS 19. ROW_NUMBER - Ranking your data. 20. DATE_TRUNC / DATE_DIFF - Finding the time between events. 21. CONCAT) - Combine strings. 22. SUBSTRING) - Extract part of a string. #dataanalytics #dataanalysis #dataanalyst #SQL
To view or add a comment, sign in
-
-
SQL Real Scenario Questions Every Data Analyst Should Know 💡 I’ve compiled 10 important SQL questions with answers that are commonly asked in interviews and real projects. If you're preparing for Data Analyst roles, this will help you strengthen your fundamentals. Save this for later and keep practicing 🚀 #SQL #DataAnalytics #InterviewPrep #DataAnalyst #Learning #CareerGrowth
To view or add a comment, sign in
-
-
SQL Real Scenario Questions Every Data Analyst Should Know 💡 I’ve compiled 10 important SQL questions with answers that are commonly asked in interviews and real projects. If you're preparing for Data Analyst roles, this will help you strengthen your fundamentals. Save this for later and keep practicing 🚀 #SQL #DataAnalytics #InterviewPrep #DataAnalyst #Learning #CareerGrowth
To view or add a comment, sign in
-
-
Day 7: Mastering the Magic of SQL Window Functions! Today was a game-changer in my SQL journey. I dived deep into Window Functions, and I finally understand why they are a data analyst's best friend. Unlike standard aggregate functions, these allow me to look at individual rows while still calculating totals, averages, or rankings across a specific "window" of data. Key Takeaways from Today: PARTITION BY: This is like a "Group By" that doesn’t hide your rows. It breaks the data into logical chunks (e.g., grouping by Department) so the function can calculate values within those specific groups. OVER(): The "magic wand" that tells SQL, "Treat this as a window function." It defines exactly which rows the function should look at. RANK(): Perfect for finding the "Top N" items. It assigns a rank to each row based on a specific order. Window Frames (The "Rules"): I explored how to define moving windows using: ROWS PRECEDING: Looking back at previous rows. CURRENT ROW: Including the data right where we are. FOLLOWING: Peeking ahead. Why this matters? This is how we calculate Running Totals, Moving Averages, and Year-over-Year growth effortlessly. It’s the difference between seeing a flat table and seeing the story and trends within the data. Feeling more confident with every query! #SQL #DataAnalytics #LearningJourney #WomenInTech #DataScience #ContinuousLearning #SQLWindowFunctions
To view or add a comment, sign in
-
🚀 Day 3 of My SQL Journey – Thinking Like a Data Analyst Today, I moved beyond basic filtering and started working with logical operators in SQL. This is where things started to feel more like real data analysis. 🔍 What I practiced: Combining conditions using AND & OR Filtering data using IN for multiple values Using LIKE for pattern matching Writing more flexible and dynamic queries 💡 Key Insight: SQL is not just about retrieving data — it’s about applying logic to answer real questions. Example questions I explored: Which employees meet multiple conditions at once? How can I filter names based on patterns? How do I simplify queries using IN instead of multiple OR statements? This stage really showed me how analysts narrow down large datasets into meaningful insights. #SQL #DataAnalytics #LearningJourney #MySQL #AspiringDataAnalyst #DataSkills
To view or add a comment, sign in
-
-
🚀 DAY 15/30 – Window Functions (SQL) Most beginners use GROUP BY… But top data analysts use Window Functions 🔥 👉 Why? Because they analyze data WITHOUT losing detail 💡 What I learned today: ✅ A window function works across a set of rows (window) ✅ It does NOT reduce rows ✅ It adds extra insights to every row ⚡ Types you must know: 🔹 Ranking Functions → RANK() | DENSE_RANK() | ROW_NUMBER() 🔹 Aggregate Functions → SUM() | AVG() | COUNT() 🔹 Value Functions → LAG() | LEAD() | FIRST_VALUE() | LAST_VALUE() 🧩 Game Changer: PARTITION BY Split data into groups 👉 Like GROUP BY But keeps all rows (this is the magic ✨) 📊 Window vs GROUP BY ❌ GROUP BY → loses detail ✅ Window Functions → keep detail + add insights 💬 Big Insight: If you want to move from SQL learner → Data Analyst, 👉 Window functions are non-negotiable #SQL #DataAnalytics #WindowFunctions #LearningInPublic #DataAnalyst
To view or add a comment, sign in
-
-
You don't need a degree to become a data analyst. You need four things — and a structured path to build them. Here's what actually moves the needle. 👇 #EdgeFoundry #DataAnalytics #CareerChange #SQL #TechCareers
To view or add a comment, sign in
-
-
🚀 Advanced SQL Challenge (Data Analyst Level) If you can solve this cleanly, you're interview-ready 👇 💡 Scenario: You have an "orders" table: - order_id - customer_id - order_date - amount 👉 Task: Write a query to find customers whose latest order amount is higher than their average order amount. ⚠️ Constraints: - Only consider customers with at least 3 orders - Handle duplicate order_date correctly (latest = max date, but ties possible) - Output: - customer_id - latest_order_amount - avg_order_amount --- 🔥 Bonus (real challenge): - Solve using window functions only (no subqueries) - Then rewrite using CTEs - Optimize for large datasets (millions of rows) --- 💭 Why this matters: This tests: - Window functions - Aggregation logic - Real-world thinking (not just syntax) Most candidates fail here — not because SQL is hard, but because thinking in data is. 👇 Drop your query. I’ll review the best ones. #SQL #DataAnalytics #AdvancedSQL #DataAnalyst #InterviewPrep #Analytics #LearnSQL
To view or add a comment, sign in
-
-
🚀 SQL Tips & Tricks – Day 6 Continuing my journey of mastering real-world SQL scenarios to become a better Data Analyst 💻📊 📌 Today’s Focus: ✔️ Swapping column values using a single UPDATE query ✔️ Handling real-time data updates using SCD Type 1 🔹 What I Practiced Today: 👉 Used CASE WHEN inside UPDATE to safely swap values in one go 👉 Understood why multiple UPDATE queries can lead to data loss 👉 Applied Slowly Changing Dimension (Type 1) to maintain only latest data 👉 Learned the importance of a precise WHERE clause to avoid critical errors 💡 Key Takeaway: A small mistake in UPDATE queries can impact the entire dataset — writing optimized and safe queries is a must-have skill for every data professional. Grateful to Ankit Bansal and Shashank Singh 🇮🇳 Singh for the valuable insights 🙌 #SQL #DataAnalytics #DataAnalyst #SQLPractice #LearningJourney #InterviewPreparation #Analytics #TechSkills #SQLTips #LinkedInLearning
To view or add a comment, sign in
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development