Essential Data Science Concepts Everyone Should Know:
1. Data Types and Structures:
• Categorical: Nominal (unordered, e.g., colors) and Ordinal (ordered, e.g., education levels)
• Numerical: Discrete (countable, e.g., number of children) and Continuous (measurable, e.g., height)
• Data Structures: Arrays, Lists, Dictionaries, DataFrames (for organizing and manipulating data)
2. Descriptive Statistics:
• Measures of Central Tendency: Mean, Median, Mode (describing the typical value)
• Measures of Dispersion: Variance, Standard Deviation, Range (describing the spread of data)
• Visualizations: Histograms, Boxplots, Scatterplots (for understanding data distribution)
3. Probability and Statistics:
• Probability Distributions: Normal, Binomial, Poisson (modeling data patterns)
• Hypothesis Testing: Formulating and testing claims about data (e.g., A/B testing)
• Confidence Intervals: Estimating the range of plausible values for a population parameter
4. Machine Learning:
• Supervised Learning: Regression (predicting continuous values) and Classification (predicting categories)
• Unsupervised Learning: Clustering (grouping similar data points) and Dimensionality Reduction (simplifying data)
• Model Evaluation: Accuracy, Precision, Recall, F1-score (assessing model performance)
5. Data Cleaning and Preprocessing:
• Missing Value Handling: Imputation, Deletion (dealing with incomplete data)
• Outlier Detection and Removal: Identifying and addressing extreme values
• Feature Engineering: Creating new features from existing ones (e.g., combining variables)
6. Data Visualization:
• Types of Charts: Bar charts, Line charts, Pie charts, Heatmaps (for communicating insights visually)
• Principles of Effective Visualization: Clarity, Accuracy, Aesthetics (for conveying information effectively)
7. Ethical Considerations in Data Science:
• Data Privacy and Security: Protecting sensitive information
• Bias and Fairness: Ensuring algorithms are unbiased and fair
8. Programming Languages and Tools:
• Python: Popular for data science with libraries like NumPy, Pandas, Scikit-learn
• R: Statistical programming language with strong visualization capabilities
• SQL: For querying and manipulating data in databases
9. Big Data and Cloud Computing:
• Hadoop and Spark: Frameworks for processing massive datasets
• Cloud Platforms: AWS, Azure, Google Cloud (for storing and analyzing data)
10. Domain Expertise:
• Understanding the Data: Knowing the context and meaning of data is crucial for effective analysis
• Problem Framing: Defining the right questions and objectives for data-driven decision making
Bonus:
• Data Storytelling: Communicating insights and findings in a clear and engaging manner
Best Data Science & Machine Learning Resources: https://topmate.io/coding/914624
ENJOY LEARNING 👍👍
1. Data Types and Structures:
• Categorical: Nominal (unordered, e.g., colors) and Ordinal (ordered, e.g., education levels)
• Numerical: Discrete (countable, e.g., number of children) and Continuous (measurable, e.g., height)
• Data Structures: Arrays, Lists, Dictionaries, DataFrames (for organizing and manipulating data)
2. Descriptive Statistics:
• Measures of Central Tendency: Mean, Median, Mode (describing the typical value)
• Measures of Dispersion: Variance, Standard Deviation, Range (describing the spread of data)
• Visualizations: Histograms, Boxplots, Scatterplots (for understanding data distribution)
3. Probability and Statistics:
• Probability Distributions: Normal, Binomial, Poisson (modeling data patterns)
• Hypothesis Testing: Formulating and testing claims about data (e.g., A/B testing)
• Confidence Intervals: Estimating the range of plausible values for a population parameter
4. Machine Learning:
• Supervised Learning: Regression (predicting continuous values) and Classification (predicting categories)
• Unsupervised Learning: Clustering (grouping similar data points) and Dimensionality Reduction (simplifying data)
• Model Evaluation: Accuracy, Precision, Recall, F1-score (assessing model performance)
5. Data Cleaning and Preprocessing:
• Missing Value Handling: Imputation, Deletion (dealing with incomplete data)
• Outlier Detection and Removal: Identifying and addressing extreme values
• Feature Engineering: Creating new features from existing ones (e.g., combining variables)
6. Data Visualization:
• Types of Charts: Bar charts, Line charts, Pie charts, Heatmaps (for communicating insights visually)
• Principles of Effective Visualization: Clarity, Accuracy, Aesthetics (for conveying information effectively)
7. Ethical Considerations in Data Science:
• Data Privacy and Security: Protecting sensitive information
• Bias and Fairness: Ensuring algorithms are unbiased and fair
8. Programming Languages and Tools:
• Python: Popular for data science with libraries like NumPy, Pandas, Scikit-learn
• R: Statistical programming language with strong visualization capabilities
• SQL: For querying and manipulating data in databases
9. Big Data and Cloud Computing:
• Hadoop and Spark: Frameworks for processing massive datasets
• Cloud Platforms: AWS, Azure, Google Cloud (for storing and analyzing data)
10. Domain Expertise:
• Understanding the Data: Knowing the context and meaning of data is crucial for effective analysis
• Problem Framing: Defining the right questions and objectives for data-driven decision making
Bonus:
• Data Storytelling: Communicating insights and findings in a clear and engaging manner
Best Data Science & Machine Learning Resources: https://topmate.io/coding/914624
ENJOY LEARNING 👍👍
❤1
Most Asked SQL Interview Questions at MAANG Companies🔥🔥
Preparing for an SQL Interview at MAANG Companies? Here are some crucial SQL Questions you should be ready to tackle:
1. How do you retrieve all columns from a table?
SELECT * FROM table_name;
2. What SQL statement is used to filter records?
SELECT * FROM table_name
WHERE condition;
The WHERE clause is used to filter records based on a specified condition.
3. How can you join multiple tables? Describe different types of JOINs.
SELECT columns
FROM table1
JOIN table2 ON table1.column = table2.column
JOIN table3 ON table2.column = table3.column;
Types of JOINs:
1. INNER JOIN: Returns records with matching values in both tables
SELECT * FROM table1
INNER JOIN table2 ON table1.column = table2.column;
2. LEFT JOIN: Returns all records from the left table & matched records from the right table. Unmatched records will have NULL values.
SELECT * FROM table1
LEFT JOIN table2 ON table1.column = table2.column;
3. RIGHT JOIN: Returns all records from the right table & matched records from the left table. Unmatched records will have NULL values.
SELECT * FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;
4. FULL JOIN: Returns records when there is a match in either left or right table. Unmatched records will have NULL values.
SELECT * FROM table1
FULL JOIN table2 ON table1.column = table2.column;
4. What is the difference between WHERE & HAVING clauses?
WHERE: Filters records before any groupings are made.
SELECT * FROM table_name
WHERE condition;
HAVING: Filters records after groupings are made.
SELECT column, COUNT(*)
FROM table_name
GROUP BY column
HAVING COUNT(*) > value;
5. How do you calculate average, sum, minimum & maximum values in a column?
Average: SELECT AVG(column_name) FROM table_name;
Sum: SELECT SUM(column_name) FROM table_name;
Minimum: SELECT MIN(column_name) FROM table_name;
Maximum: SELECT MAX(column_name) FROM table_name;
Here you can find essential SQL Interview Resources👇
https://t.me/mysqldata
Like this post if you need more 👍❤️
Hope it helps :)
Preparing for an SQL Interview at MAANG Companies? Here are some crucial SQL Questions you should be ready to tackle:
1. How do you retrieve all columns from a table?
SELECT * FROM table_name;
2. What SQL statement is used to filter records?
SELECT * FROM table_name
WHERE condition;
The WHERE clause is used to filter records based on a specified condition.
3. How can you join multiple tables? Describe different types of JOINs.
SELECT columns
FROM table1
JOIN table2 ON table1.column = table2.column
JOIN table3 ON table2.column = table3.column;
Types of JOINs:
1. INNER JOIN: Returns records with matching values in both tables
SELECT * FROM table1
INNER JOIN table2 ON table1.column = table2.column;
2. LEFT JOIN: Returns all records from the left table & matched records from the right table. Unmatched records will have NULL values.
SELECT * FROM table1
LEFT JOIN table2 ON table1.column = table2.column;
3. RIGHT JOIN: Returns all records from the right table & matched records from the left table. Unmatched records will have NULL values.
SELECT * FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;
4. FULL JOIN: Returns records when there is a match in either left or right table. Unmatched records will have NULL values.
SELECT * FROM table1
FULL JOIN table2 ON table1.column = table2.column;
4. What is the difference between WHERE & HAVING clauses?
WHERE: Filters records before any groupings are made.
SELECT * FROM table_name
WHERE condition;
HAVING: Filters records after groupings are made.
SELECT column, COUNT(*)
FROM table_name
GROUP BY column
HAVING COUNT(*) > value;
5. How do you calculate average, sum, minimum & maximum values in a column?
Average: SELECT AVG(column_name) FROM table_name;
Sum: SELECT SUM(column_name) FROM table_name;
Minimum: SELECT MIN(column_name) FROM table_name;
Maximum: SELECT MAX(column_name) FROM table_name;
Here you can find essential SQL Interview Resources👇
https://t.me/mysqldata
Like this post if you need more 👍❤️
Hope it helps :)
❤2
What is the difference between data scientist, data engineer, data analyst and business intelligence?
🧑🔬 Data Scientist
Focus: Using data to build models, make predictions, and solve complex problems.
Cleans and analyzes data
Builds machine learning models
Answers “Why is this happening?” and “What will happen next?”
Works with statistics, algorithms, and coding (Python, R)
Example: Predict which customers are likely to cancel next month
🛠️ Data Engineer
Focus: Building and maintaining the systems that move and store data.
Designs and builds data pipelines (ETL/ELT)
Manages databases, data lakes, and warehouses
Ensures data is clean, reliable, and ready for others to use
Uses tools like SQL, Airflow, Spark, and cloud platforms (AWS, Azure, GCP)
Example: Create a system that collects app data every hour and stores it in a warehouse
📊 Data Analyst
Focus: Exploring data and finding insights to answer business questions.
Pulls and visualizes data (dashboards, reports)
Answers “What happened?” or “What’s going on right now?”
Works with SQL, Excel, and tools like Tableau or Power BI
Less coding and modeling than a data scientist
Example: Analyze monthly sales and show trends by region
📈 Business Intelligence (BI) Professional
Focus: Helping teams and leadership understand data through reports and dashboards.
Designs dashboards and KPIs (key performance indicators)
Translates data into stories for non-technical users
Often overlaps with data analyst role but more focused on reporting
Tools: Power BI, Looker, Tableau, Qlik
Example: Build a dashboard showing company performance by department
🧩 Summary Table
Data Scientist - What will happen? Tools: Python, R, ML tools, predictions & models
Data Engineer - How does the data move and get stored? Tools: SQL, Spark, cloud tools, infrastructure & pipelines
Data Analyst - What happened? Tools: SQL, Excel, BI tools, reports & exploration
BI Professional - How can we see business performance clearly? Tools: Power BI, Tableau, dashboards & insights for decision-makers
🎯 In short:
Data Engineers build the roads.
Data Scientists drive smart cars to predict traffic.
Data Analysts look at traffic data to see patterns.
BI Professionals show everyone the traffic report on a screen.
🧑🔬 Data Scientist
Focus: Using data to build models, make predictions, and solve complex problems.
Cleans and analyzes data
Builds machine learning models
Answers “Why is this happening?” and “What will happen next?”
Works with statistics, algorithms, and coding (Python, R)
Example: Predict which customers are likely to cancel next month
🛠️ Data Engineer
Focus: Building and maintaining the systems that move and store data.
Designs and builds data pipelines (ETL/ELT)
Manages databases, data lakes, and warehouses
Ensures data is clean, reliable, and ready for others to use
Uses tools like SQL, Airflow, Spark, and cloud platforms (AWS, Azure, GCP)
Example: Create a system that collects app data every hour and stores it in a warehouse
📊 Data Analyst
Focus: Exploring data and finding insights to answer business questions.
Pulls and visualizes data (dashboards, reports)
Answers “What happened?” or “What’s going on right now?”
Works with SQL, Excel, and tools like Tableau or Power BI
Less coding and modeling than a data scientist
Example: Analyze monthly sales and show trends by region
📈 Business Intelligence (BI) Professional
Focus: Helping teams and leadership understand data through reports and dashboards.
Designs dashboards and KPIs (key performance indicators)
Translates data into stories for non-technical users
Often overlaps with data analyst role but more focused on reporting
Tools: Power BI, Looker, Tableau, Qlik
Example: Build a dashboard showing company performance by department
🧩 Summary Table
Data Scientist - What will happen? Tools: Python, R, ML tools, predictions & models
Data Engineer - How does the data move and get stored? Tools: SQL, Spark, cloud tools, infrastructure & pipelines
Data Analyst - What happened? Tools: SQL, Excel, BI tools, reports & exploration
BI Professional - How can we see business performance clearly? Tools: Power BI, Tableau, dashboards & insights for decision-makers
🎯 In short:
Data Engineers build the roads.
Data Scientists drive smart cars to predict traffic.
Data Analysts look at traffic data to see patterns.
BI Professionals show everyone the traffic report on a screen.
❤2
📊 Data Science Summarized: The Core Pillars of Success! 🚀
✅ 1️⃣ Statistics:
The backbone of data analysis and decision-making.
Used for hypothesis testing, distributions, and drawing actionable insights.
✅ 2️⃣ Mathematics:
Critical for building models and understanding algorithms.
Focus on:
Linear Algebra
Calculus
Probability & Statistics
✅ 3️⃣ Python:
The most widely used language in data science.
Essential libraries include:
Pandas
NumPy
Scikit-Learn
TensorFlow
✅ 4️⃣ Machine Learning:
Use algorithms to uncover patterns and make predictions.
Key types:
Regression
Classification
Clustering
✅ 5️⃣ Domain Knowledge:
Context matters.
Understand your industry to build relevant, useful, and accurate models.
✅ 1️⃣ Statistics:
The backbone of data analysis and decision-making.
Used for hypothesis testing, distributions, and drawing actionable insights.
✅ 2️⃣ Mathematics:
Critical for building models and understanding algorithms.
Focus on:
Linear Algebra
Calculus
Probability & Statistics
✅ 3️⃣ Python:
The most widely used language in data science.
Essential libraries include:
Pandas
NumPy
Scikit-Learn
TensorFlow
✅ 4️⃣ Machine Learning:
Use algorithms to uncover patterns and make predictions.
Key types:
Regression
Classification
Clustering
✅ 5️⃣ Domain Knowledge:
Context matters.
Understand your industry to build relevant, useful, and accurate models.
❤1
Here’s a detailed breakdown of critical roles and their associated responsibilities:
🔘 Data Engineer: Tailored for Data Enthusiasts
1. Data Ingestion: Acquire proficiency in data handling techniques.
2. Data Validation: Master the art of data quality assurance.
3. Data Cleansing: Learn advanced data cleaning methodologies.
4. Data Standardisation: Grasp the principles of data formatting.
5. Data Curation: Efficiently organise and manage datasets.
🔘 Data Scientist: Suited for Analytical Minds
6. Feature Extraction: Hone your skills in identifying data patterns.
7. Feature Selection: Master techniques for efficient feature selection.
8. Model Exploration: Dive into the realm of model selection methodologies.
🔘 Data Scientist & ML Engineer: Designed for Coding Enthusiasts
9. Coding Proficiency: Develop robust programming skills.
10. Model Training: Understand the intricacies of model training.
11. Model Validation: Explore various model validation techniques.
12. Model Evaluation: Master the art of evaluating model performance.
13. Model Refinement: Refine and improve candidate models.
14. Model Selection: Learn to choose the most suitable model for a given task.
🔘 ML Engineer: Tailored for Deployment Enthusiasts
15. Model Packaging: Acquire knowledge of essential packaging techniques.
16. Model Registration: Master the process of model tracking and registration.
17. Model Containerisation: Understand the principles of containerisation.
18. Model Deployment: Explore strategies for effective model deployment.
These roles encompass diverse facets of Data and ML, catering to various interests and skill sets. Delve into these domains, identify your passions, and customise your learning journey accordingly.
🔘 Data Engineer: Tailored for Data Enthusiasts
1. Data Ingestion: Acquire proficiency in data handling techniques.
2. Data Validation: Master the art of data quality assurance.
3. Data Cleansing: Learn advanced data cleaning methodologies.
4. Data Standardisation: Grasp the principles of data formatting.
5. Data Curation: Efficiently organise and manage datasets.
🔘 Data Scientist: Suited for Analytical Minds
6. Feature Extraction: Hone your skills in identifying data patterns.
7. Feature Selection: Master techniques for efficient feature selection.
8. Model Exploration: Dive into the realm of model selection methodologies.
🔘 Data Scientist & ML Engineer: Designed for Coding Enthusiasts
9. Coding Proficiency: Develop robust programming skills.
10. Model Training: Understand the intricacies of model training.
11. Model Validation: Explore various model validation techniques.
12. Model Evaluation: Master the art of evaluating model performance.
13. Model Refinement: Refine and improve candidate models.
14. Model Selection: Learn to choose the most suitable model for a given task.
🔘 ML Engineer: Tailored for Deployment Enthusiasts
15. Model Packaging: Acquire knowledge of essential packaging techniques.
16. Model Registration: Master the process of model tracking and registration.
17. Model Containerisation: Understand the principles of containerisation.
18. Model Deployment: Explore strategies for effective model deployment.
These roles encompass diverse facets of Data and ML, catering to various interests and skill sets. Delve into these domains, identify your passions, and customise your learning journey accordingly.
❤3
𝐊𝐮𝐛𝐞𝐫𝐧𝐞𝐭𝐞𝐬 𝐓𝐞𝐜𝐡 𝐒𝐭𝐚𝐜𝐤
What it is: A powerful open-source platform designed to automate deploying, scaling, and operating application containers.
𝐂𝐥𝐮𝐬𝐭𝐞𝐫 𝐌𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭:
- Organizes containers into groups for easier management.
- Automates tasks like scaling and load balancing.
𝐂𝐨𝐧𝐭𝐚𝐢𝐧𝐞𝐫 𝐑𝐮𝐧𝐭𝐢𝐦𝐞:
- Software responsible for launching and managing containers.
- Ensures containers run efficiently and securely.
𝐒𝐞𝐜𝐮𝐫𝐢𝐭𝐲:
- Implements measures to protect against unauthorized access and malicious activities.
- Includes features like role-based access control and encryption.
𝐌𝐨𝐧𝐢𝐭𝐨𝐫𝐢𝐧𝐠 & 𝐎𝐛𝐬𝐞𝐫𝐯𝐚𝐛𝐢𝐥𝐢𝐭𝐲:
- Tools to monitor system health, performance, and resource usage.
- Helps identify and troubleshoot issues quickly.
𝐍𝐞𝐭𝐰𝐨𝐫𝐤𝐢𝐧𝐠:
- Manages network communication between containers and external systems.
- Ensures connectivity and security between different parts of the system.
𝐈𝐧𝐟𝐫𝐚𝐬𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐞 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬:
- Handles tasks related to the underlying infrastructure, such as provisioning and scaling.
- Automates repetitive tasks to streamline operations and improve efficiency.
- 𝐊𝐞𝐲 𝐜𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭𝐬:
- Cluster Management: Handles grouping and managing multiple containers.
- Container Runtime: Software that runs containers and manages their lifecycle.
- Security: Implements measures to protect containers and the overall system.
- Monitoring & Observability: Tools to track and understand system behavior and performance.
- Networking: Manages communication between containers and external networks.
- Infrastructure Operations: Handles tasks like provisioning, scaling, and maintaining the underlying infrastructure.
What it is: A powerful open-source platform designed to automate deploying, scaling, and operating application containers.
𝐂𝐥𝐮𝐬𝐭𝐞𝐫 𝐌𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭:
- Organizes containers into groups for easier management.
- Automates tasks like scaling and load balancing.
𝐂𝐨𝐧𝐭𝐚𝐢𝐧𝐞𝐫 𝐑𝐮𝐧𝐭𝐢𝐦𝐞:
- Software responsible for launching and managing containers.
- Ensures containers run efficiently and securely.
𝐒𝐞𝐜𝐮𝐫𝐢𝐭𝐲:
- Implements measures to protect against unauthorized access and malicious activities.
- Includes features like role-based access control and encryption.
𝐌𝐨𝐧𝐢𝐭𝐨𝐫𝐢𝐧𝐠 & 𝐎𝐛𝐬𝐞𝐫𝐯𝐚𝐛𝐢𝐥𝐢𝐭𝐲:
- Tools to monitor system health, performance, and resource usage.
- Helps identify and troubleshoot issues quickly.
𝐍𝐞𝐭𝐰𝐨𝐫𝐤𝐢𝐧𝐠:
- Manages network communication between containers and external systems.
- Ensures connectivity and security between different parts of the system.
𝐈𝐧𝐟𝐫𝐚𝐬𝐭𝐫𝐮𝐜𝐭𝐮𝐫𝐞 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬:
- Handles tasks related to the underlying infrastructure, such as provisioning and scaling.
- Automates repetitive tasks to streamline operations and improve efficiency.
- 𝐊𝐞𝐲 𝐜𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭𝐬:
- Cluster Management: Handles grouping and managing multiple containers.
- Container Runtime: Software that runs containers and manages their lifecycle.
- Security: Implements measures to protect containers and the overall system.
- Monitoring & Observability: Tools to track and understand system behavior and performance.
- Networking: Manages communication between containers and external networks.
- Infrastructure Operations: Handles tasks like provisioning, scaling, and maintaining the underlying infrastructure.
❤2
Netflix Analytics Engineer Interview Question (SQL) 🚀
---
### Scenario Overview
Netflix wants to analyze user engagement with their platform. Imagine you have a table called
-
-
-
-
-
-
The main objective is to figure out how to get insights into user behavior, such as which genres are most popular or how watch duration varies across subscription plans.
---
### Typical Interview Question
> “Using the
This question tests your ability to:
1. Filter or group data by subscription plan.
2. Calculate average watch duration within each group.
3. Sort results to find the “top 3” within each group.
4. Handle tie situations or edge cases (e.g., if there are fewer than 3 genres).
---
### Step-by-Step Approach
1. Group and Aggregate
Use the
2. Rank Genres
You can utilize a window function—commonly
(Note that in many SQL dialects, you’ll need a subquery because you can’t directly apply an aggregate in the ORDER BY of a window function.)
3. Select Top 3
After ranking rows in each partition (i.e., subscription plan), pick only the top 3 by watch duration. This could look like:
4. Validate Results
- Make sure each subscription plan returns up to 3 genres.
- Check for potential ties. Depending on the question, you might use
- Confirm the data type and units for
---
### Key Takeaways
- Window Functions: Essential for ranking or partitioning data.
- Aggregations & Grouping: A foundational concept for Analytics Engineers.
- Data Validation: Always confirm you’re interpreting columns (like
By mastering these techniques, you’ll be better prepared for SQL interview questions that delve into real-world scenarios—especially at a data-driven company like Netflix.
---
### Scenario Overview
Netflix wants to analyze user engagement with their platform. Imagine you have a table called
netflix_data with the following columns:-
user_id: Unique identifier for each user-
subscription_plan: Type of subscription (e.g., Basic, Standard, Premium)-
genre: Genre of the content the user watched (e.g., Drama, Comedy, Action)-
timestamp: Date and time when the user watched a show-
watch_duration: Length of time (in minutes) a user spent watching-
country: User’s countryThe main objective is to figure out how to get insights into user behavior, such as which genres are most popular or how watch duration varies across subscription plans.
---
### Typical Interview Question
> “Using the
netflix_data table, find the top 3 genres by average watch duration in each subscription plan, and return both the genre and the average watch duration.”This question tests your ability to:
1. Filter or group data by subscription plan.
2. Calculate average watch duration within each group.
3. Sort results to find the “top 3” within each group.
4. Handle tie situations or edge cases (e.g., if there are fewer than 3 genres).
---
### Step-by-Step Approach
1. Group and Aggregate
Use the
GROUP BY clause to group by subscription_plan and genre. Then, use an aggregate function like AVG(watch_duration) to get the average watch time for each combination.2. Rank Genres
You can utilize a window function—commonly
ROW_NUMBER() or RANK()—to assign a ranking to each genre within its subscription plan, based on the average watch duration. For example:AVG(watch_duration) OVER (PARTITION BY subscription_plan ORDER BY AVG(watch_duration) DESC)
(Note that in many SQL dialects, you’ll need a subquery because you can’t directly apply an aggregate in the ORDER BY of a window function.)
3. Select Top 3
After ranking rows in each partition (i.e., subscription plan), pick only the top 3 by watch duration. This could look like:
SELECT subscription_plan,
genre,
avg_watch_duration
FROM (
SELECT subscription_plan,
genre,
AVG(watch_duration) AS avg_watch_duration,
ROW_NUMBER() OVER (
PARTITION BY subscription_plan
ORDER BY AVG(watch_duration) DESC
) AS rn
FROM netflix_data
GROUP BY subscription_plan, genre
) ranked
WHERE rn <= 3;
4. Validate Results
- Make sure each subscription plan returns up to 3 genres.
- Check for potential ties. Depending on the question, you might use
RANK() or DENSE_RANK() to handle ties differently. - Confirm the data type and units for
watch_duration (minutes, seconds, etc.).---
### Key Takeaways
- Window Functions: Essential for ranking or partitioning data.
- Aggregations & Grouping: A foundational concept for Analytics Engineers.
- Data Validation: Always confirm you’re interpreting columns (like
watch_duration) correctly. By mastering these techniques, you’ll be better prepared for SQL interview questions that delve into real-world scenarios—especially at a data-driven company like Netflix.
❤6