The 3 SQL queries every data analyst should have saved: 1️⃣ Find duplicate records instantly SELECT column, COUNT(*) as cnt FROM table GROUP BY column HAVING COUNT(*) > 1 2️⃣ Running totals (without complex window functions) SELECT date, revenue, SUM(revenue) OVER (ORDER BY date) as running_total FROM sales 3️⃣ Find gaps in sequential IDs SELECT id+1 as missing_from FROM table t1 WHERE NOT EXISTS ( SELECT 1 FROM table t2 WHERE t2.id = t1.id + 1 ) Save this post. You'll use these weekly. What's your most-used SQL trick? Drop it below 👇 #SQL #DataAnalytics #DataEngineering #JustHiveData #Python
3 Essential SQL Queries for Data Analysts: Duplicates, Running Totals, and Gaps
More Relevant Posts
-
Here are some must-know Pandas functions that every analyst should have at their fingertips: Data Loading `read_csv()` | `read_excel()` Quick Exploration `head()` | `info()` | `describe()` | `shape` Data Cleaning `isnull()` | `dropna()` | `fillna()` | `drop_duplicates()` Data Transformation `rename()` | `astype()` | `apply()` Data Analysis `groupby()` | `pivot_table()` | `value_counts()` Data Selection `loc[]` | `iloc[]` | `query()` Data Merging `merge()` | `concat()` #Pandas #Python #DataAnalytics #DataScience #Learning #CareerGrowth #DataEngineer #ExcelToPython
To view or add a comment, sign in
-
-
I would like to share with you this business question and its answer using SQL. the question is: Who are highest-value customers, and what behaviors define them? Understanding the top 10% by revenue helps the business prioritize retention, personalize outreach, and optimize product strategy. This PDF breaks down a SQL-based approach to: - Identify highest-value customers by revenue - See what they actually buy (top product category) - Use NTILE and CTEs for clean, actionable segmentation This is the DWH GitHub repo link which I implemented using Python and SQL Server: https://lnkd.in/dSgxVPPT #Business_Intelligence #Data_Engineering #ETL #Data_Warehouse #Python #SQL #SQLServer #Data_Modeling #SCD
To view or add a comment, sign in
-
🧹 Day 3/7 – Data Cleaning = Data Quality Before validating… clean your data. Focused on: 🔹 Data inspection (info, describe) 🔹 Handling missing values 🔹 Filtering datasets 🔹 Removing duplicates 💡 Sample code snippets: Data Inspection: print(df.info()) print(df.describe()) 🎯 Understand data before validating it. Handling Missing Values: df.fillna(0, inplace=True) 🎯 Missing data = common ETL issue Filtering Data: df[df["age"] > 18] 🎯 Apply business rules easily Removing Duplicates: df.drop_duplicates(inplace=True) 🎯 Ensures clean datasets 🎯 Key takeaway: Bad data in = bad insights out. Cleaning is not optional. #DataCleaning #DataQuality #Python #Analytics #ETL
To view or add a comment, sign in
-
-
I asked for “a simple dataset.” The dataset said: “You sure about that?” Column names? `price`, `Price`, `PRICE`, `pr1ce`… why not? Missing values? Oh, they were there… just hiding like they pay rent. Duplicates? Same house listed 4 times—with different prices. Even the data was confused. At this point, I wasn’t doing data analysis anymore… I was doing therapy. But after cleaning it—fixing columns, handling nulls, removing duplicates—everything changed. Suddenly, the data started making sense. Patterns appeared. Insights showed up. And it reminded me: 80% of data analysis is cleaning. The other 20% is explaining why the first 80% took so long. If you’re learning data analysis and struggling with messy data… you’re not alone. That’s the job. Portfolio: [https://lnkd.in/dDijzXP9) #DataAnalytics #DataCleaning #Python #SQL #Excel #DataAnalyst #LearningInPublic
To view or add a comment, sign in
-
-
Understanding the difference between LAG and LEAD in SQL 🚀 If you’re preparing for SQL interviews or working with data analysis, mastering window functions is a must! 🔹 LAG() → Fetches data from the previous row 🔹 LEAD() → Fetches data from the next row These functions are super useful for: ✅ Comparing current vs previous values ✅ Finding trends over time ✅ Analyzing sequential data 💡 Pro Tip: Use them with OVER (ORDER BY column) to control how rows are processed. Mastering this can really level up your SQL game 💯 #SQL #DataAnalytics #DataScience #LearnSQL #SQLFunctions #WindowFunctions #LAG #LEAD #TechSkills #InterviewPreparation #LinkedInLearning #CareerGrowth #DataAnalyst #SQLTips #Programming
To view or add a comment, sign in
-
-
A SQL query that calls itself! Sounds like a bug. It's actually a superpower: 𝗥𝗲𝗰𝘂𝗿𝘀𝗶𝘃𝗲 𝗖𝗧𝗘𝘀! A recursive CTE is a Common Table Expression that selects from itself. Seems tricky, but it's actually not that difficult! Imagine you have this company hierarchy: Alice (CEO) ↳ Bob and Charlie report to Alice ↳ David and Eve report to Bob ↳ Frank and Grace report to Charlie You can build this entire corporate tree with SQL! Showing each employee and their level in the hierarchy. Behind the SQL scenes: 1️⃣ The base case gets the top of the hierarchy (Alice). 2️⃣ Then the CTE calls itself to find everyone reporting to her. 3️⃣ Each new “generation” of employees adds one more level. 4️⃣ The process continues until there are no more subordinates. That’s recursion! 🔄 The most powerful way to handle hierarchical data. 𝟭𝟬𝟬 𝗦𝗤𝗟 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 + 𝟯𝟬𝟬 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗲 𝗘𝘅𝗮𝗺𝗽𝗹𝗲𝘀 + 𝗡𝗼𝘁𝗲𝘀 𝟭𝟬𝟬 𝗘𝘅𝗰𝗲𝗹 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 + 𝗡𝗼𝘁𝗲𝘀 + 𝗙𝗼𝗿𝗺𝘂𝗹𝗮 𝗦𝗵𝗲𝗲𝘁 𝟭𝟱𝟬 𝗣𝘆𝘁𝗵𝗼𝗻 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 (𝗡𝘂𝗺𝗣𝘆 + 𝗣𝗮𝗻𝗱𝗮𝘀 + 𝗠𝗮𝘁𝗽𝗹𝗼𝘁𝗹𝗶𝗯) 𝟭𝟬𝟬 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 + 𝗗𝗔𝗫 𝗖𝗵𝗲𝗮𝘁 𝗦𝗵𝗲𝗲𝘁 + 𝗡𝗼𝘁𝗲𝘀 𝟭𝟬𝟬 𝗧𝗼𝗽 𝗛𝗥 𝗥𝗼𝘂𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 𝟭𝟬𝟬 𝗦𝘁𝗮𝘁𝗶𝘀𝘁𝗶𝗰𝘀 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤&𝗔 + 𝗡𝗼𝘁𝗲𝘀 𝗥𝗲𝘀𝘂𝗺𝗲 𝗚𝘂𝗶𝗱𝗲 + 𝟳𝟬𝟬 𝗖𝗼𝗺𝗽𝗮𝗻𝘆 𝗦𝗶𝘁𝗲𝘀 𝗚𝗲𝘁 𝗔𝗰𝗰𝗲𝘀𝘀 𝗛𝗲𝗿𝗲: https://lnkd.in/dyBfCTjK #datascience #data #dataanalysis #sql #python #pandas #excel #powerbi
To view or add a comment, sign in
-
-
💡 Mastering SQL, one query at a time! From basic SELECT statements to complex joins and window functions, every query brings me closer to turning raw data into meaningful insights. 📊 🔹 Data is powerful, but SQL is the key to unlock it 🔹 Practice. Optimize. Repeat. 🔹 Turning questions into answers with queries Follow Suraj Patankar for more #SQL #DataAnalytics #SQLServer #InterviewPreparation #BusinessIntelligence #DataAnalyst #PowerBI #DAX #DataAnalytics #DataAnalyst #PowerBIDeveloper #BusinessIntelligence #MicrosoftFabric #Analytics #CareerGrowth #Python #Excel #DataScience #DataEngineer
To view or add a comment, sign in
-
Just published my first technical article on Medium! Topic: How to Use CTEs in SQL, one of the most underused tools in data analytics. If you've ever written a messy nested subquery, this is for you 👇 https://lnkd.in/gHZ4nJCt Would love your feedback, drop a comment or share with someone learning SQL! #SQL #DataAnalytics #DataScience #Python #PowerBI
To view or add a comment, sign in
-
Unpopular opinion: Knowing SQL, Power BI, or Python alone doesn’t make you a Data Analyst. What truly matters is your ability to ask the right questions, understand business problems, and turn raw data into actionable insights. Tools help you analyze data. Thinking helps you create impact. Agree or disagree? 👇 #DataAnalyst #DataAnalytics #SQL #PowerBI #PythonForDataAnalysis #BusinessThinking #AnalyticsCareer #DataDrivenDecisions #CareerGrowth #LinkedInCommunity
To view or add a comment, sign in
-
Most BI dashboards show you what happened yesterday. I wanted to know what was happening right now. So I built a pipeline that pulls live data from an external API, loads it directly into a PostgreSQL table, and refreshes automatically every 30 minutes via a scheduled job. The dashboard connected to it stopped being a report. It became a live operational tool. The technical setup was straightforward: → REST API endpoint returning JSON → Python script to parse, validate, and insert records → Scheduled job configured to run every 30 minutes → Power BI connected directly to the PostgreSQL table The interesting part was not the code. It was watching how people used the dashboard differently once they knew the data was live. They stopped waiting for the morning report and started making decisions during the day. Real-time data does not just speed up reporting. It changes behaviour. #SQL #Python #PowerBI #DataEngineering #BusinessIntelligence #DataAnalyst
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