This is much easier to maintain than repeatedly writing [Total Sales].
๐น 12. Best Practices
When writing complex DAX:
โ Give variables meaningful names
โ Break complicated calculations into logical steps
โ Avoid repeating the same expression
โ Use RETURN for the final result
โ Keep business logic readable
โ Use variables to make debugging easier
Avoid meaningless names such as VAR X =...
Prefer VAR TotalSales =...
Clear names make your DAX easier for another analyst to understand.
๐ฏ Interview Questions
1๏ธโฃ What is VAR in DAX?
VAR creates a temporary variable that stores a value or table expression during calculation.
2๏ธโฃ What does RETURN do?
It specifies the final expression that the measure should return.
3๏ธโฃ Are DAX variables stored permanently in the model?
No. Variables exist only during the evaluation of the expression.
4๏ธโฃ Why should you use variables?
They improve readability, reduce repeated calculations, and make complex DAX easier to debug.
5๏ธโฃ Can a DAX variable contain a table?
Yes. A variable can store either a scalar value or a table expression.
๐งช PRACTICE
Create these measures using VAR:
โ Total Profit
โ Profit Margin
โ Sales Target Status
โ Sales Performance
โ Selected Region Message
Then try to rewrite one of your older complex DAX measures using variables.
๐ก Double Tap โค๏ธ For More
๐น 12. Best Practices
When writing complex DAX:
โ Give variables meaningful names
โ Break complicated calculations into logical steps
โ Avoid repeating the same expression
โ Use RETURN for the final result
โ Keep business logic readable
โ Use variables to make debugging easier
Avoid meaningless names such as VAR X =...
Prefer VAR TotalSales =...
Clear names make your DAX easier for another analyst to understand.
๐ฏ Interview Questions
1๏ธโฃ What is VAR in DAX?
VAR creates a temporary variable that stores a value or table expression during calculation.
2๏ธโฃ What does RETURN do?
It specifies the final expression that the measure should return.
3๏ธโฃ Are DAX variables stored permanently in the model?
No. Variables exist only during the evaluation of the expression.
4๏ธโฃ Why should you use variables?
They improve readability, reduce repeated calculations, and make complex DAX easier to debug.
5๏ธโฃ Can a DAX variable contain a table?
Yes. A variable can store either a scalar value or a table expression.
๐งช PRACTICE
Create these measures using VAR:
โ Total Profit
โ Profit Margin
โ Sales Target Status
โ Sales Performance
โ Selected Region Message
Then try to rewrite one of your older complex DAX measures using variables.
๐ก Double Tap โค๏ธ For More
โค3๐1
๐ Data Analyst Interview Series โ Part 1
Guys, let's start a Data Analyst Interview Series where I'll cover the most important questions that are commonly asked in Data Analyst interviews.
I'll cover SQL, Excel, Power BI, Python, statistics, data cleaning, case studies, business questions, and scenario-based questions.
Let's start with the basics ๐
1๏ธโฃ Tell me about yourself.
Sample Answer:
"I'm a Data Analyst with experience working with SQL, Excel, Power BI, Python, and data visualization. My work involves extracting and transforming data, analyzing business problems, building dashboards, and automating repetitive reporting processes. I focus not just on creating reports, but on understanding the business requirement and converting data into actionable insights."
2๏ธโฃ What does a Data Analyst do?
Sample Answer:
"A Data Analyst collects, cleans, transforms, and analyzes data to help businesses make informed decisions. A typical workflow involves understanding the business requirement, collecting relevant data, cleaning it, performing analysis, identifying trends or patterns, and presenting the findings through reports or dashboards."
3๏ธโฃ What is the difference between Data Analysis and Data Analytics?
Sample Answer:
"Data analysis generally focuses on examining data to understand what happened and why. Data analytics is a broader concept that includes data analysis along with processes such as data collection, preparation, visualization, statistical analysis, and sometimes predictive modeling. In practice, the terms are often used interchangeably depending on the organization."
4๏ธโฃ What is the difference between structured and unstructured data?
Sample Answer:
"Structured data has a predefined format or schema, such as rows and columns in a relational database. Examples include customer IDs, transaction amounts, and dates.
Unstructured data does not follow a predefined tabular structure. Examples include emails, images, videos, documents, and social media posts.
Semi-structured data sits between the two, such as JSON and XML, where the data has some organizational structure but doesn't necessarily follow a relational table format."
5๏ธโฃ What is data cleaning and why is it important?
Sample Answer:
"Data cleaning is the process of identifying and correcting problems in a dataset, such as missing values, duplicates, inconsistent formats, incorrect data types, and invalid values.
It is important because analysis performed on poor-quality data can produce misleading results. Before analyzing data, I would first understand the data quality issues and determine how each issue should be handled based on the business context."
6๏ธโฃ How do you handle missing values?
Sample Answer:
"I first investigate why the values are missing and how much data is affected. The appropriate treatment depends on the business context.
For example, I might remove records if only a very small number are affected and they aren't important to the analysis. For numerical fields, I might use an appropriate statistical value such as median or mean when justified. For categorical fields, I might use a meaningful category such as 'Unknown.'
I avoid blindly replacing missing values because missingness itself can sometimes contain useful information."
7๏ธโฃ How do you identify duplicate records?
Sample Answer:
"I first determine what defines a unique record. Then I compare the relevant columns or business key to identify duplicates.
For example, if Customer_ID and Transaction_ID together uniquely identify a transaction, I can use those fields to identify duplicate combinations.
In SQL, I could use GROUP BY with HAVING COUNT(**) > 1 to identify duplicated keys."
Guys, let's start a Data Analyst Interview Series where I'll cover the most important questions that are commonly asked in Data Analyst interviews.
I'll cover SQL, Excel, Power BI, Python, statistics, data cleaning, case studies, business questions, and scenario-based questions.
Let's start with the basics ๐
1๏ธโฃ Tell me about yourself.
Sample Answer:
"I'm a Data Analyst with experience working with SQL, Excel, Power BI, Python, and data visualization. My work involves extracting and transforming data, analyzing business problems, building dashboards, and automating repetitive reporting processes. I focus not just on creating reports, but on understanding the business requirement and converting data into actionable insights."
2๏ธโฃ What does a Data Analyst do?
Sample Answer:
"A Data Analyst collects, cleans, transforms, and analyzes data to help businesses make informed decisions. A typical workflow involves understanding the business requirement, collecting relevant data, cleaning it, performing analysis, identifying trends or patterns, and presenting the findings through reports or dashboards."
3๏ธโฃ What is the difference between Data Analysis and Data Analytics?
Sample Answer:
"Data analysis generally focuses on examining data to understand what happened and why. Data analytics is a broader concept that includes data analysis along with processes such as data collection, preparation, visualization, statistical analysis, and sometimes predictive modeling. In practice, the terms are often used interchangeably depending on the organization."
4๏ธโฃ What is the difference between structured and unstructured data?
Sample Answer:
"Structured data has a predefined format or schema, such as rows and columns in a relational database. Examples include customer IDs, transaction amounts, and dates.
Unstructured data does not follow a predefined tabular structure. Examples include emails, images, videos, documents, and social media posts.
Semi-structured data sits between the two, such as JSON and XML, where the data has some organizational structure but doesn't necessarily follow a relational table format."
5๏ธโฃ What is data cleaning and why is it important?
Sample Answer:
"Data cleaning is the process of identifying and correcting problems in a dataset, such as missing values, duplicates, inconsistent formats, incorrect data types, and invalid values.
It is important because analysis performed on poor-quality data can produce misleading results. Before analyzing data, I would first understand the data quality issues and determine how each issue should be handled based on the business context."
6๏ธโฃ How do you handle missing values?
Sample Answer:
"I first investigate why the values are missing and how much data is affected. The appropriate treatment depends on the business context.
For example, I might remove records if only a very small number are affected and they aren't important to the analysis. For numerical fields, I might use an appropriate statistical value such as median or mean when justified. For categorical fields, I might use a meaningful category such as 'Unknown.'
I avoid blindly replacing missing values because missingness itself can sometimes contain useful information."
7๏ธโฃ How do you identify duplicate records?
Sample Answer:
"I first determine what defines a unique record. Then I compare the relevant columns or business key to identify duplicates.
For example, if Customer_ID and Transaction_ID together uniquely identify a transaction, I can use those fields to identify duplicate combinations.
In SQL, I could use GROUP BY with HAVING COUNT(**) > 1 to identify duplicated keys."
SELECT Customer_ID, Transaction_ID, COUNT(**) AS duplicate_count
FROM transactions
GROUP BY Customer_ID, Transaction_ID
HAVING COUNT(**) > 1;
โค8
"After identifying duplicates, I investigate whether they are genuine duplicate records or legitimate repeated transactions before removing anything."
8๏ธโฃ What is an outlier? How would you handle it?
Sample Answer:
"An outlier is a value that is significantly different from the typical observations in a dataset.
I wouldn't automatically remove an outlier. First, I would investigate whether it represents a data-quality issue or a genuine business event.
For example, a transaction worth โน10 million might initially look like an outlier, but it could be a legitimate high-value transaction. If it is a data-entry error, I would correct or exclude it according to the business rules."
9๏ธโฃ What is the difference between a dimension and a measure?
Sample Answer:
"A dimension is generally used to categorize or describe data, while a measure is a numerical value that can usually be aggregated.
For example, in a sales dataset:
Dimensions: Customer, Product, Region, Date
Measures: Sales Amount, Quantity, Profit, Discount
In a dashboard, dimensions are commonly used to slice or group the data, while measures are used to calculate KPIs and metrics."
๐ What steps do you follow when solving a data analysis problem?
Sample Answer:
"I generally follow a structured approach:
1. Understand the business problem.
2. Define the required metrics and success criteria.
3. Identify the relevant data sources.
4. Extract and validate the data.
5. Clean and transform the data.
6. Perform exploratory analysis.
7. Identify trends, patterns, and anomalies.
8. Validate the results.
9. Communicate the insights using appropriate visualizations.
10. Recommend actions based on the findings.
The most important step is understanding the business question first, because technically correct analysis can still be useless if it doesn't answer the actual business problem."
๐ Double Tap โค๏ธ For Part-2
8๏ธโฃ What is an outlier? How would you handle it?
Sample Answer:
"An outlier is a value that is significantly different from the typical observations in a dataset.
I wouldn't automatically remove an outlier. First, I would investigate whether it represents a data-quality issue or a genuine business event.
For example, a transaction worth โน10 million might initially look like an outlier, but it could be a legitimate high-value transaction. If it is a data-entry error, I would correct or exclude it according to the business rules."
9๏ธโฃ What is the difference between a dimension and a measure?
Sample Answer:
"A dimension is generally used to categorize or describe data, while a measure is a numerical value that can usually be aggregated.
For example, in a sales dataset:
Dimensions: Customer, Product, Region, Date
Measures: Sales Amount, Quantity, Profit, Discount
In a dashboard, dimensions are commonly used to slice or group the data, while measures are used to calculate KPIs and metrics."
๐ What steps do you follow when solving a data analysis problem?
Sample Answer:
"I generally follow a structured approach:
1. Understand the business problem.
2. Define the required metrics and success criteria.
3. Identify the relevant data sources.
4. Extract and validate the data.
5. Clean and transform the data.
6. Perform exploratory analysis.
7. Identify trends, patterns, and anomalies.
8. Validate the results.
9. Communicate the insights using appropriate visualizations.
10. Recommend actions based on the findings.
The most important step is understanding the business question first, because technically correct analysis can still be useless if it doesn't answer the actual business problem."
๐ Double Tap โค๏ธ For Part-2
โค13
๐๐ฅ๐๐ ๐ฅ๐ฒ๐๐ผ๐๐ฟ๐ฐ๐ฒ๐ ๐ง๐ผ ๐๐ฒ๐ฎ๐ฟ๐ป ๐๐ ๐ถ๐ป ๐ฎ๐ฌ๐ฎ๐ฒ๐
โ
Explore 6 free resources covering AI fundamentals, tools, deep learning, research and real-world applications.
โ 100% Free Learning
โ Beginner-Friendly
โ AI โข ML โข Deep Learning
โ Real-World Applications
๐ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/4AFHq5R
๐ข Share this valuable opportunity with your friends and classmates!
โ
Explore 6 free resources covering AI fundamentals, tools, deep learning, research and real-world applications.
โ 100% Free Learning
โ Beginner-Friendly
โ AI โข ML โข Deep Learning
โ Real-World Applications
๐ ๐๐ ๐ฝ๐น๐ผ๐ฟ๐ฒ ๐๐ฅ๐๐ ๐๐ผ๐๐ฟ๐๐ฒ๐ ๐
https://pdlink.in/4AFHq5R
๐ข Share this valuable opportunity with your friends and classmates!
โค2
๐ Data Analyst Interview Series โ Part 2
Guys, let's continue our Data Analyst Interview Series.
In Part 2, let's move into some important SQL and data-related interview questions that are frequently tested in Data Analyst interviews. ๐
1๏ธโฃ What is SQL and why is it important for a Data Analyst?
Sample Answer:
"SQL stands for Structured Query Language. It is used to interact with relational databases. As a Data Analyst, I use SQL to retrieve, filter, join, aggregate, and analyze data. It is important because a large amount of business data is stored in databases, and SQL allows analysts to efficiently extract the data required for analysis."
2๏ธโฃ What is the difference between WHERE and HAVING?
Sample Answer:
"WHERE filters individual rows before aggregation, whereas HAVING filters groups after aggregation.
For example, if I want to find customers whose total sales exceed โน1 lakh, I would use HAVING because the condition is applied to an aggregated result."
3๏ธโฃ What is the difference between INNER JOIN and LEFT JOIN?
Sample Answer:
"An INNER JOIN returns only the records that have matching values in both tables.
A LEFT JOIN returns all records from the left table and the matching records from the right table. If there is no match, the columns from the right table contain NULL."
For example, if I want all customers, including customers who haven't placed any orders, I would use a LEFT JOIN.
4๏ธโฃ What is a primary key?
Sample Answer:
"A primary key is a column or combination of columns that uniquely identifies each record in a table. It must contain unique values and cannot contain NULL values.
For example, Customer_ID can be a primary key in a Customer table if every customer has a unique ID."
5๏ธโฃ What is a foreign key?
Sample Answer:
"A foreign key is a column that references a primary key or another unique key in another table. It establishes a relationship between tables.
For example, Customer_ID in an Orders table can reference Customer_ID in the Customers table."
6๏ธโฃ What is the difference between UNION and UNION ALL?
Sample Answer:
"Both are used to combine the results of two or more SELECT statements.
UNION removes duplicate records from the combined result, while UNION ALL retains duplicates.
Because UNION performs duplicate elimination, UNION ALL can generally be faster when duplicate removal isn't required."
7๏ธโฃ What is a NULL value in SQL?
Sample Answer:
"NULL represents a missing, unknown, or unavailable value. It is different from zero, an empty string, or a blank value.
We should use IS NULL or IS NOT NULL to check for NULL values rather than using an equals operator."
8๏ธโฃ What is GROUP BY used for?
Sample Answer:
"GROUP BY is used to group rows that have the same values in one or more columns so that aggregate functions can be applied to each group.
For example, to calculate total sales by region:"
9๏ธโฃ What are aggregate functions in SQL?
Sample Answer:
"Aggregate functions perform calculations on multiple rows and return a single result for each group.
Common aggregate functions include:"
โข COUNT() โ counts records
โข SUM() โ calculates the total
โข AVG() โ calculates the average
โข MIN() โ finds the minimum value
โข MAX() โ finds the maximum value
For example:
Guys, let's continue our Data Analyst Interview Series.
In Part 2, let's move into some important SQL and data-related interview questions that are frequently tested in Data Analyst interviews. ๐
1๏ธโฃ What is SQL and why is it important for a Data Analyst?
Sample Answer:
"SQL stands for Structured Query Language. It is used to interact with relational databases. As a Data Analyst, I use SQL to retrieve, filter, join, aggregate, and analyze data. It is important because a large amount of business data is stored in databases, and SQL allows analysts to efficiently extract the data required for analysis."
2๏ธโฃ What is the difference between WHERE and HAVING?
Sample Answer:
"WHERE filters individual rows before aggregation, whereas HAVING filters groups after aggregation.
For example, if I want to find customers whose total sales exceed โน1 lakh, I would use HAVING because the condition is applied to an aggregated result."
SELECT Customer_ID, SUM(Sales) AS Total_Sales
FROM Sales
GROUP BY Customer_ID
HAVING SUM(Sales) > 100000;
3๏ธโฃ What is the difference between INNER JOIN and LEFT JOIN?
Sample Answer:
"An INNER JOIN returns only the records that have matching values in both tables.
A LEFT JOIN returns all records from the left table and the matching records from the right table. If there is no match, the columns from the right table contain NULL."
For example, if I want all customers, including customers who haven't placed any orders, I would use a LEFT JOIN.
4๏ธโฃ What is a primary key?
Sample Answer:
"A primary key is a column or combination of columns that uniquely identifies each record in a table. It must contain unique values and cannot contain NULL values.
For example, Customer_ID can be a primary key in a Customer table if every customer has a unique ID."
5๏ธโฃ What is a foreign key?
Sample Answer:
"A foreign key is a column that references a primary key or another unique key in another table. It establishes a relationship between tables.
For example, Customer_ID in an Orders table can reference Customer_ID in the Customers table."
6๏ธโฃ What is the difference between UNION and UNION ALL?
Sample Answer:
"Both are used to combine the results of two or more SELECT statements.
UNION removes duplicate records from the combined result, while UNION ALL retains duplicates.
Because UNION performs duplicate elimination, UNION ALL can generally be faster when duplicate removal isn't required."
7๏ธโฃ What is a NULL value in SQL?
Sample Answer:
"NULL represents a missing, unknown, or unavailable value. It is different from zero, an empty string, or a blank value.
We should use IS NULL or IS NOT NULL to check for NULL values rather than using an equals operator."
SELECT *
FROM Customers
WHERE Email IS NULL;
8๏ธโฃ What is GROUP BY used for?
Sample Answer:
"GROUP BY is used to group rows that have the same values in one or more columns so that aggregate functions can be applied to each group.
For example, to calculate total sales by region:"
SELECT Region, SUM(Sales) AS Total_Sales
FROM Sales
GROUP BY Region;
9๏ธโฃ What are aggregate functions in SQL?
Sample Answer:
"Aggregate functions perform calculations on multiple rows and return a single result for each group.
Common aggregate functions include:"
โข COUNT() โ counts records
โข SUM() โ calculates the total
โข AVG() โ calculates the average
โข MIN() โ finds the minimum value
โข MAX() โ finds the maximum value
For example:
SELECT
COUNT(*) AS Total_Orders,
SUM(Sales) AS Total_Sales,
AVG(Sales) AS Average_Sales
FROM Sales;
โค6
๐ How would you find duplicate records in SQL?
Sample Answer:
"I would first identify the column or combination of columns that should uniquely identify a record. Then I would use GROUP BY and HAVING COUNT(*) > 1."
"This identifies Customer_ID values that appear more than once. I would then investigate whether those records are genuine duplicates before taking any corrective action."
๐ Double Tap โค๏ธ For Part-3
Sample Answer:
"I would first identify the column or combination of columns that should uniquely identify a record. Then I would use GROUP BY and HAVING COUNT(*) > 1."
SELECT Customer_ID, COUNT(*) AS Count_Records
FROM Customers
GROUP BY Customer_ID
HAVING COUNT(*) > 1;
"This identifies Customer_ID values that appear more than once. I would then investigate whether those records are genuine duplicates before taking any corrective action."
๐ Double Tap โค๏ธ For Part-3
โค16
๐ Data Analyst Interview Series โ Part 3
Guys, let's continue our Data Analyst Interview Series.
Today, let's cover 10 important SQL interview questions that test your practical SQL knowledge. ๐
1๏ธโฃ What is a subquery in SQL?
Sample Answer:
โA subquery is a query written inside another SQL query. It can be used to retrieve intermediate results that are then used by the outer query.
For example, to find employees whose salary is greater than the average salary:โ
2๏ธโฃ What is a CTE?
Sample Answer:
โCTE stands for Common Table Expression. It allows us to define a temporary named result set using the WITH clause, which can then be referenced within the main query.
CTEs make complex queries easier to read, maintain, and debug.โ
3๏ธโฃ What is a window function?
Sample Answer:
โA window function performs a calculation across a set of related rows while still retaining the individual rows in the result.
Unlike GROUP BY, it does not collapse multiple rows into a single row.
Common window functions include ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), and LEAD().โ
4๏ธโฃ What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?
Sample Answer:
โROW_NUMBER() assigns a unique sequential number to every row.
RANK() assigns the same rank to tied values but leaves gaps after a tie.
DENSE_RANK() also assigns the same rank to tied values but does not leave gaps.โ
Example:
Values: 100, 100, 90
ROW_NUMBER: 1, 2, 3
RANK: 1, 1, 3
DENSE_RANK: 1, 1, 2
5๏ธโฃ How would you find the second-highest salary?
Sample Answer:
โOne approach is to use DENSE_RANK(). This also handles duplicate salaries correctly.โ
6๏ธโฃ How would you find the top 3 salaries in each department?
Sample Answer:
โI would use a window function to rank employees within each department.โ
โThe PARTITION BY ensures that ranking starts separately for each department.โ
7๏ธโฃ What is PARTITION BY in SQL?
Sample Answer:
โPARTITION BY divides the result set into groups for a window function without collapsing the rows.
For example, if I want to rank employees separately within each department, I can use PARTITION BY Department.โ
8๏ธโฃ What are LAG() and LEAD() functions?
Sample Answer:
โLAG() allows me to access a value from a previous row, while LEAD() allows me to access a value from a following row.
They are particularly useful for comparing current values with previous or future values, such as month-over-month sales.โ
Guys, let's continue our Data Analyst Interview Series.
Today, let's cover 10 important SQL interview questions that test your practical SQL knowledge. ๐
1๏ธโฃ What is a subquery in SQL?
Sample Answer:
โA subquery is a query written inside another SQL query. It can be used to retrieve intermediate results that are then used by the outer query.
For example, to find employees whose salary is greater than the average salary:โ
SELECT Employee_ID, Salary
FROM Employees
WHERE Salary > (
SELECT AVG(Salary)
FROM Employees
);
2๏ธโฃ What is a CTE?
Sample Answer:
โCTE stands for Common Table Expression. It allows us to define a temporary named result set using the WITH clause, which can then be referenced within the main query.
CTEs make complex queries easier to read, maintain, and debug.โ
WITH CustomerSales AS (
SELECT Customer_ID,
SUM(Sales) AS Total_Sales
FROM Sales
GROUP BY Customer_ID
)
SELECT *
FROM CustomerSales
WHERE Total_Sales > 100000;
3๏ธโฃ What is a window function?
Sample Answer:
โA window function performs a calculation across a set of related rows while still retaining the individual rows in the result.
Unlike GROUP BY, it does not collapse multiple rows into a single row.
Common window functions include ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), and LEAD().โ
4๏ธโฃ What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?
Sample Answer:
โROW_NUMBER() assigns a unique sequential number to every row.
RANK() assigns the same rank to tied values but leaves gaps after a tie.
DENSE_RANK() also assigns the same rank to tied values but does not leave gaps.โ
Example:
Values: 100, 100, 90
ROW_NUMBER: 1, 2, 3
RANK: 1, 1, 3
DENSE_RANK: 1, 1, 2
5๏ธโฃ How would you find the second-highest salary?
Sample Answer:
โOne approach is to use DENSE_RANK(). This also handles duplicate salaries correctly.โ
WITH RankedEmployees AS (
SELECT Employee_ID,
Salary,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS Salary_Rank
FROM Employees
)
SELECT Employee_ID, Salary
FROM RankedEmployees
WHERE Salary_Rank = 2;
6๏ธโฃ How would you find the top 3 salaries in each department?
Sample Answer:
โI would use a window function to rank employees within each department.โ
WITH RankedEmployees AS (
SELECT Employee_ID,
Department,
Salary,
DENSE_RANK() OVER (
PARTITION BY Department
ORDER BY Salary DESC
) AS Salary_Rank
FROM Employees
)
SELECT *
FROM RankedEmployees
WHERE Salary_Rank <= 3;
โThe PARTITION BY ensures that ranking starts separately for each department.โ
7๏ธโฃ What is PARTITION BY in SQL?
Sample Answer:
โPARTITION BY divides the result set into groups for a window function without collapsing the rows.
For example, if I want to rank employees separately within each department, I can use PARTITION BY Department.โ
SELECT Employee_ID,
Department,
Salary,
RANK() OVER (
PARTITION BY Department
ORDER BY Salary DESC
) AS Salary_Rank
FROM Employees;
8๏ธโฃ What are LAG() and LEAD() functions?
Sample Answer:
โLAG() allows me to access a value from a previous row, while LEAD() allows me to access a value from a following row.
They are particularly useful for comparing current values with previous or future values, such as month-over-month sales.โ
SELECT Month,
Sales,
LAG(Sales) OVER (ORDER BY Month) AS Previous_Month_Sales
FROM Monthly_Sales;
โค4
9๏ธโฃ How would you calculate month-over-month growth?
Sample Answer:
โI would first retrieve the previous month's sales using LAG(), then calculate the percentage change between the current month and previous month.โ
โI would also handle cases where the previous month's value is zero or NULL to avoid incorrect calculations.โ
๐ What is the difference between DELETE, TRUNCATE, and DROP?
Sample Answer:
โDELETE removes selected rows from a table and can be used with a WHERE condition.
TRUNCATE removes all rows from a table while keeping the table structure.
DROP removes the entire table, including its structure and data.
So, the key difference is whether I'm removing specific records, all records, or the entire table itself.โ
๐ Double Tap โค๏ธ For Part-4
Sample Answer:
โI would first retrieve the previous month's sales using LAG(), then calculate the percentage change between the current month and previous month.โ
SELECT Month,
Sales,
LAG(Sales) OVER (ORDER BY Month) AS Previous_Sales,
(Sales - LAG(Sales) OVER (ORDER BY Month))
* 100.0 /
LAG(Sales) OVER (ORDER BY Month) AS MoM_Growth
FROM Monthly_Sales;
โI would also handle cases where the previous month's value is zero or NULL to avoid incorrect calculations.โ
๐ What is the difference between DELETE, TRUNCATE, and DROP?
Sample Answer:
โDELETE removes selected rows from a table and can be used with a WHERE condition.
TRUNCATE removes all rows from a table while keeping the table structure.
DROP removes the entire table, including its structure and data.
So, the key difference is whether I'm removing specific records, all records, or the entire table itself.โ
๐ Double Tap โค๏ธ For Part-4
โค19
๐ ๐ฎ๐๐๐ฒ๐ฟ ๐ฃ๐ผ๐๐ฒ๐ฟ ๐๐ ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐! ๐ฅ
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
Learn Power BI through these FREE learning resources
โ
โจ What You'll Learn:
๐ Interactive Dashboards
๐ Data Visualization
๐งน Data Transformation
๐ผ Real-World Reporting Skills
๐ฏ Beginner-Friendly โ No Coding Required
๐ฆ๐๐ฎ๐ฟ๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด ๐ณ๐ผ๐ฟ ๐๐ฅ๐๐
โ
โhttps://pdlink.in/4hznwlu
๐ซPerfect for Students โข Freshers โข Data Analyst Aspirants โข Working Professionals
๐ Data Analyst Interview Series โ Part 4
Guys, let's continue our Data Analyst Interview Series.
Today, let's cover 10 practical SQL questions that are commonly asked in Data Analyst interviews. ๐
1๏ธโฃ How do you find the highest salary in each department?
Sample Answer:
"I would use a window function such as DENSE_RANK() and partition the data by department."
2๏ธโฃ How do you find customers who have never placed an order?
Sample Answer:
"I would use a LEFT JOIN between the Customers and Orders tables and then filter for customers where no matching order exists."
3๏ธโฃ How do you find the total sales for each customer?
Sample Answer:
"I would group the sales data by Customer_ID and use SUM() to calculate the total sales."
4๏ธโฃ How do you find the top 5 customers by sales?
Sample Answer:
"I would aggregate sales by customer, sort the result in descending order, and then return the top five customers."
"The exact syntax for limiting rows can vary depending on the database, such as TOP in SQL Server."
5๏ธโฃ How do you calculate the average order value?
Sample Answer:
"Average Order Value can be calculated by dividing total sales by the number of orders. If each row represents one order, AVG() can also be used directly on the order amount."
6๏ธโฃ How would you identify customers who placed more than 5 orders?
Sample Answer:
"I would group the orders by Customer_ID and use HAVING to filter customers whose order count is greater than five."
7๏ธโฃ How do you find records from the last 30 days?
Sample Answer:
"I would compare the date column with the current date and subtract 30 days. The exact syntax depends on the database."
For example:
8๏ธโฃ How do you find the total sales by month?
Sample Answer:
"I would extract the month from the order date, group the data by month, and calculate the total sales."
9๏ธโฃ How do you find employees whose salary is above their department's average salary?
Sample Answer:
"I would calculate the average salary for each department and compare each employee's salary with that department-level average. A CTE makes this easier to read."
Guys, let's continue our Data Analyst Interview Series.
Today, let's cover 10 practical SQL questions that are commonly asked in Data Analyst interviews. ๐
1๏ธโฃ How do you find the highest salary in each department?
Sample Answer:
"I would use a window function such as DENSE_RANK() and partition the data by department."
WITH RankedEmployees AS (
SELECT Employee_ID,
Department,
Salary,
DENSE_RANK() OVER (
PARTITION BY Department
ORDER BY Salary DESC
) AS Salary_Rank
FROM Employees
)
SELECT Employee_ID, Department, Salary
FROM RankedEmployees
WHERE Salary_Rank = 1;
2๏ธโฃ How do you find customers who have never placed an order?
Sample Answer:
"I would use a LEFT JOIN between the Customers and Orders tables and then filter for customers where no matching order exists."
SELECT c.Customer_ID,
c.Customer_Name
FROM Customers c
LEFT JOIN Orders o
ON c.Customer_ID = o.Customer_ID
WHERE o.Customer_ID IS NULL;
3๏ธโฃ How do you find the total sales for each customer?
Sample Answer:
"I would group the sales data by Customer_ID and use SUM() to calculate the total sales."
SELECT Customer_ID,
SUM(Sales) AS Total_Sales
FROM Orders
GROUP BY Customer_ID;
4๏ธโฃ How do you find the top 5 customers by sales?
Sample Answer:
"I would aggregate sales by customer, sort the result in descending order, and then return the top five customers."
SELECT Customer_ID,
SUM(Sales) AS Total_Sales
FROM Orders
GROUP BY Customer_ID
ORDER BY Total_Sales DESC
LIMIT 5;
"The exact syntax for limiting rows can vary depending on the database, such as TOP in SQL Server."
5๏ธโฃ How do you calculate the average order value?
Sample Answer:
"Average Order Value can be calculated by dividing total sales by the number of orders. If each row represents one order, AVG() can also be used directly on the order amount."
SELECT AVG(Order_Amount) AS Average_Order_Value
FROM Orders;
6๏ธโฃ How would you identify customers who placed more than 5 orders?
Sample Answer:
"I would group the orders by Customer_ID and use HAVING to filter customers whose order count is greater than five."
SELECT Customer_ID,
COUNT(**) AS Order_Count
FROM Orders
GROUP BY Customer_ID
HAVING COUNT(**) > 5;
7๏ธโฃ How do you find records from the last 30 days?
Sample Answer:
"I would compare the date column with the current date and subtract 30 days. The exact syntax depends on the database."
For example:
SELECT **
FROM Orders
WHERE Order_Date >= CURRENT_DATE - INTERVAL '30' DAY;
8๏ธโฃ How do you find the total sales by month?
Sample Answer:
"I would extract the month from the order date, group the data by month, and calculate the total sales."
SELECT
DATE_TRUNC('month', Order_Date) AS Month,
SUM(Sales) AS Total_Sales
FROM Orders
GROUP BY DATE_TRUNC('month', Order_Date)
ORDER BY Month;
9๏ธโฃ How do you find employees whose salary is above their department's average salary?
Sample Answer:
"I would calculate the average salary for each department and compare each employee's salary with that department-level average. A CTE makes this easier to read."
WITH DepartmentAverage AS (
SELECT Department,
AVG(Salary) AS Avg_Salary
FROM Employees
GROUP BY Department
)
SELECT e.Employee_ID,
e.Department,
e.Salary
FROM Employees e
JOIN DepartmentAverage d
ON e.Department = d.Department
WHERE e.Salary > d.Avg_Salary;
๐2โค1
๐ What is the difference between UNION and JOIN?
Sample Answer:
"JOIN combines columns from different tables based on a related key.
UNION combines rows from the results of two SELECT statements with compatible column structures.
For example, if I want to combine customer information with order information, I would typically use a JOIN. If I want to append two similar datasets containing the same type of records, I might use UNION."
๐ Double Tap โค๏ธ For Part 5
Sample Answer:
"JOIN combines columns from different tables based on a related key.
UNION combines rows from the results of two SELECT statements with compatible column structures.
For example, if I want to combine customer information with order information, I would typically use a JOIN. If I want to append two similar datasets containing the same type of records, I might use UNION."
๐ Double Tap โค๏ธ For Part 5
โค7
๐๐ฃ๐ฎ๐ ๐๐ณ๐๐ฒ๐ฟ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐ง๐ฟ๐ฎ๐ถ๐ป๐ถ๐ป๐ด | ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ ๐๐๐น๐น๐๐๐ฎ๐ฐ๐ธ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ ๐ช๐๐๐ต ๐๐ฒ๐ป๐๐
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
Start a high-paying tech careerโeven without prior coding experience
๐ ๐ฃ๐น๐ฎ๐ฐ๐ฒ๐บ๐ฒ๐ป๐ ๐๐ถ๐ด๐ต๐น๐ถ๐ด๐ต๐๐:
๐ฐ โน41 LPA highest salary
๐ โน7.4 LPA average salary
๐ 2,000+ students placed
๐ข 500+ hiring partners
โ 100% job assistance
๐ Skill Indiaโauthenticated certificate
๐ ๐๐ฝ๐ฝ๐น๐ ๐ก๐ผ๐๐:-
https://pdlink.in/3SuUeuD
๐ฏ HurryUp.....Limited Seats Available
โค2