
Get clients in any niche!
Delegate the launch of advertising to us — for free
Learn more
7.1

Advertising on the Telegram channel «SQL MySQL Interviews»
Computer science
Language:
English
0
0
This channel covers everything you need to learn SQL for data science, data analyst, data engineer and business analyst roles.
Share
Add to favorite
Buy advertising in this channel
Placement Format:
keyboard_arrow_down
- 1/24
- 2/48
- 3/72
- Native
- 7 days
- Forwards
1 hour in the top / 24 hours in the feed
Quantity
%keyboard_arrow_down
- 1
- 2
- 3
- 4
- 5
- 8
- 10
- 15
Advertising publication cost
local_activity
$2.40$2.40local_mall
0.0%
Remaining at this price:0
Recent Channel Posts
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.
549
12:20
19.02.2025
SQL Tricks to Level Up Your Database Skills 🚀
SQL is a powerful language, but mastering a few clever tricks can make your queries faster, cleaner, and more efficient. Here are some cool SQL hacks to boost your skills:
1️⃣ Use COALESCE Instead of CASE
Instead of writing a long
This returns the first non-null value in the list.
2️⃣ Generate Sequential Numbers Without a Table
Need a sequence of numbers but don’t have a numbers table? Use
3️⃣ Find Duplicates Quickly
Easily identify duplicate values with
4️⃣ Randomly Select Rows
Want a random sample of data? Use:
- PostgreSQL:
- MySQL:
- SQL Server:
5️⃣ Pivot Data Without PIVOT (For Databases Without It)
Use
6️⃣ Efficiently Get the Last Inserted ID
Instead of running a separate
- MySQL:
- PostgreSQL:
- SQL Server:
SQL is full of hidden gems—what are your favorite tricks? Let’s discuss in the comments! 💬🔍 #SQL #Database
SQL is a powerful language, but mastering a few clever tricks can make your queries faster, cleaner, and more efficient. Here are some cool SQL hacks to boost your skills:
1️⃣ Use COALESCE Instead of CASE
Instead of writing a long
CASE
statement to handle NULL values, use COALESCE()
: SELECT COALESCE(name, 'Unknown') FROM users;
This returns the first non-null value in the list.
2️⃣ Generate Sequential Numbers Without a Table
Need a sequence of numbers but don’t have a numbers table? Use
GENERATE_SERIES
(PostgreSQL) or WITH RECURSIVE
(MySQL 8+): SELECT generate_series(1, 10);
3️⃣ Find Duplicates Quickly
Easily identify duplicate values with
GROUP BY
and HAVING
: SELECT email, COUNT(*)
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
4️⃣ Randomly Select Rows
Want a random sample of data? Use:
- PostgreSQL:
ORDER BY RANDOM()
- MySQL:
ORDER BY RAND()
- SQL Server:
ORDER BY NEWID()
5️⃣ Pivot Data Without PIVOT (For Databases Without It)
Use
CASE
with SUM()
to pivot data manually: SELECT
user_id,
SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS active_count,
SUM(CASE WHEN status = 'inactive' THEN 1 ELSE 0 END) AS inactive_count
FROM users
GROUP BY user_id;
6️⃣ Efficiently Get the Last Inserted ID
Instead of running a separate
SELECT
, use: - MySQL:
SELECT LAST_INSERT_ID();
- PostgreSQL:
RETURNING id;
- SQL Server:
SELECT SCOPE_IDENTITY();
SQL is full of hidden gems—what are your favorite tricks? Let’s discuss in the comments! 💬🔍 #SQL #Database
604
14:12
18.02.2025
SQL cheat sheet Crash Course.
618
03:19
17.02.2025
Essentials for Acing any Data Analytics Interviews-
SQL:
1. Beginner
- Fundamentals: SELECT, WHERE, ORDER BY, GROUP BY, HAVING
- Essential JOINS: INNER, LEFT, RIGHT, FULL
- Basics of database and table creation
2. Intermediate
- Aggregate functions: COUNT, SUM, AVG, MAX, MIN
- Subqueries and nested queries
- Common Table Expressions with the WITH clause
- Conditional logic in queries using CASE statements
3. Advanced
- Complex JOIN techniques: self-join, non-equi join
- Window functions: OVER, PARTITION BY, ROW_NUMBER, RANK, DENSE_RANK, lead, lag
- Query optimization through indexing
- Manipulating data: INSERT, UPDATE, DELETE
Python:
1. Basics
- Understanding syntax, variables, and data types: integers, floats, strings, booleans
- Control structures: if-else, loops (for, while)
- Core data structures: lists, dictionaries, sets, tuples
- Functions and error handling: lambda functions, try-except
- Using modules and packages
2. Pandas & Numpy
- DataFrames and Series: creation and manipulation
- Techniques: indexing, selecting, filtering
- Handling missing data with fillna and dropna
- Data aggregation: groupby, data summarizing
- Data merging techniques: merge, join, concatenate
3. Visualization
- Plotting basics with Matplotlib: line plots, bar plots, histograms
- Advanced visualization with Seaborn: scatter plots, box plots, pair plots
- Plot customization: sizes, labels, legends, colors
- Introduction to interactive visualizations with Plotly
Excel:
1. Basics
- Cell operations and basic formulas: SUMIFS, COUNTIFS, AVERAGEIFS
- Charts and introductory data visualization
- Data sorting and filtering, Conditional formatting
2. Intermediate
- Advanced formulas: V/XLOOKUP, INDEX-MATCH, complex IF scenarios
- Summarizing data with PivotTables and PivotCharts
- Tools for data validation and what-if analysis: Data Tables, Goal Seek
3. Advanced
- Utilizing array formulas and sophisticated functions
- Building a Data Model & using Power Pivot
- Advanced filtering, Slicers and Timelines in Pivot Tables
- Crafting dynamic charts and interactive dashboards
Power BI:
1. Data Modeling
- Importing data from diverse sources
- Creating and managing dataset relationships
- Data modeling essentials: star schema, snowflake schema
2. Data Transformation
- Data cleaning and transformation with Power Query
- Advanced data shaping techniques
- Implementing calculated columns and measures with DAX
3. Data Visualization and Reporting
- Developing interactive reports and dashboards
- Visualization types: bar, line, pie charts, maps
- Report publishing and sharing, scheduling data refreshes
Statistics:
Mean, Median, Mode, Standard Deviation, Variance, Probability Distributions, Hypothesis Testing, P-values, Confidence Intervals, Correlation, Simple Linear Regression, Normal Distribution, Binomial Distribution, Poisson Distribution
SQL:
1. Beginner
- Fundamentals: SELECT, WHERE, ORDER BY, GROUP BY, HAVING
- Essential JOINS: INNER, LEFT, RIGHT, FULL
- Basics of database and table creation
2. Intermediate
- Aggregate functions: COUNT, SUM, AVG, MAX, MIN
- Subqueries and nested queries
- Common Table Expressions with the WITH clause
- Conditional logic in queries using CASE statements
3. Advanced
- Complex JOIN techniques: self-join, non-equi join
- Window functions: OVER, PARTITION BY, ROW_NUMBER, RANK, DENSE_RANK, lead, lag
- Query optimization through indexing
- Manipulating data: INSERT, UPDATE, DELETE
Python:
1. Basics
- Understanding syntax, variables, and data types: integers, floats, strings, booleans
- Control structures: if-else, loops (for, while)
- Core data structures: lists, dictionaries, sets, tuples
- Functions and error handling: lambda functions, try-except
- Using modules and packages
2. Pandas & Numpy
- DataFrames and Series: creation and manipulation
- Techniques: indexing, selecting, filtering
- Handling missing data with fillna and dropna
- Data aggregation: groupby, data summarizing
- Data merging techniques: merge, join, concatenate
3. Visualization
- Plotting basics with Matplotlib: line plots, bar plots, histograms
- Advanced visualization with Seaborn: scatter plots, box plots, pair plots
- Plot customization: sizes, labels, legends, colors
- Introduction to interactive visualizations with Plotly
Excel:
1. Basics
- Cell operations and basic formulas: SUMIFS, COUNTIFS, AVERAGEIFS
- Charts and introductory data visualization
- Data sorting and filtering, Conditional formatting
2. Intermediate
- Advanced formulas: V/XLOOKUP, INDEX-MATCH, complex IF scenarios
- Summarizing data with PivotTables and PivotCharts
- Tools for data validation and what-if analysis: Data Tables, Goal Seek
3. Advanced
- Utilizing array formulas and sophisticated functions
- Building a Data Model & using Power Pivot
- Advanced filtering, Slicers and Timelines in Pivot Tables
- Crafting dynamic charts and interactive dashboards
Power BI:
1. Data Modeling
- Importing data from diverse sources
- Creating and managing dataset relationships
- Data modeling essentials: star schema, snowflake schema
2. Data Transformation
- Data cleaning and transformation with Power Query
- Advanced data shaping techniques
- Implementing calculated columns and measures with DAX
3. Data Visualization and Reporting
- Developing interactive reports and dashboards
- Visualization types: bar, line, pie charts, maps
- Report publishing and sharing, scheduling data refreshes
Statistics:
Mean, Median, Mode, Standard Deviation, Variance, Probability Distributions, Hypothesis Testing, P-values, Confidence Intervals, Correlation, Simple Linear Regression, Normal Distribution, Binomial Distribution, Poisson Distribution
2000
03:19
17.02.2025
Advanced SQL Optimization Tips for Data Analysts
1. Use Proper Indexing
Create indexes on frequently queried columns to speed up data retrieval.
2. Avoid `SELECT *`
Specify only the columns you need to reduce the amount of data processed.
3. Use `WHERE` Instead of `HAVING`
Filter your data as early as possible in the query to optimize performance.
4. Limit Joins
Try to keep joins to a minimum to reduce query complexity and processing time.
5. Apply `LIMIT` or `TOP`
Retrieve only the required rows to save on resources.
6. Optimize Joins
Use
7. Use Temporary Tables
Break large, complex queries into smaller parts using temporary tables.
8. Avoid Functions on Indexed Columns
Using functions on indexed columns often prevents the index from being used.
9. Use CTEs for Readability
Common Table Expressions help simplify nested queries and improve clarity.
10. Analyze Execution Plans
Leverage execution plans to identify bottlenecks and make targeted optimizations.
Happy querying!
1. Use Proper Indexing
Create indexes on frequently queried columns to speed up data retrieval.
2. Avoid `SELECT *`
Specify only the columns you need to reduce the amount of data processed.
3. Use `WHERE` Instead of `HAVING`
Filter your data as early as possible in the query to optimize performance.
4. Limit Joins
Try to keep joins to a minimum to reduce query complexity and processing time.
5. Apply `LIMIT` or `TOP`
Retrieve only the required rows to save on resources.
6. Optimize Joins
Use
INNER JOIN
instead of OUTER JOIN
whenever possible.7. Use Temporary Tables
Break large, complex queries into smaller parts using temporary tables.
8. Avoid Functions on Indexed Columns
Using functions on indexed columns often prevents the index from being used.
9. Use CTEs for Readability
Common Table Expressions help simplify nested queries and improve clarity.
10. Analyze Execution Plans
Leverage execution plans to identify bottlenecks and make targeted optimizations.
Happy querying!
1000
11:57
16.02.2025
Once you've learned/mastered the fundamentals of SQL, try learning these:
- 𝐉𝐎𝐈𝐍𝐬: LEFT, RIGHT, INNER, OUTER joins.
- 𝐀𝐠𝐠𝐫𝐞𝐠𝐚𝐭𝐞 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Utilize SUM, COUNT, AVG, and others for efficient data summarization.
- 𝐂𝐀𝐒𝐄 𝐖𝐇𝐄𝐍 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭𝐬: Use conditional logic to tailor query results.
- 𝐃𝐚𝐭𝐞 𝐓𝐢𝐦𝐞 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Master manipulating dates and times for precise analysis.
Next, explore advanced methods to structure and reuse SQL code effectively:
- 𝐂𝐨𝐦𝐦𝐨𝐧 𝐓𝐚𝐛𝐥𝐞 𝐄𝐱𝐩𝐫𝐞𝐬𝐬𝐢𝐨𝐧𝐬 (𝐂𝐓𝐄𝐬): Simplify complex queries into manageable parts to increase the readability.
- 𝐒𝐮𝐛𝐪𝐮𝐞𝐫𝐢𝐞𝐬: Nest queries for more granular data retrieval.
- 𝐓𝐞𝐦𝐩𝐨𝐫𝐚𝐫𝐲 𝐓𝐚𝐛𝐥𝐞𝐬: Create and manipulate temporary data sets for specific tasks.
Then, move on to advanced ones:
- 𝐖𝐢𝐧𝐝𝐨𝐰 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Perform advanced calculations over sets of rows with ease.
- 𝐒𝐭𝐨𝐫𝐞𝐝 𝐏𝐫𝐨𝐜𝐞𝐝𝐮𝐫𝐞𝐬: Create reusable SQL routines for streamlined operations.
- 𝐓𝐫𝐢𝐠𝐠𝐞𝐫𝐬: Automate database actions based on specific events.
- 𝐑𝐞𝐜𝐮𝐫𝐬𝐢𝐯𝐞 𝐂𝐓𝐄𝐬: Solve complex problems using recursive queries.
- 𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐚𝐭𝐢𝐨𝐧 𝐨𝐟 𝐐𝐮𝐞𝐫𝐢𝐞𝐬: Techniques to enhance performance and efficiency.
- 𝐉𝐎𝐈𝐍𝐬: LEFT, RIGHT, INNER, OUTER joins.
- 𝐀𝐠𝐠𝐫𝐞𝐠𝐚𝐭𝐞 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Utilize SUM, COUNT, AVG, and others for efficient data summarization.
- 𝐂𝐀𝐒𝐄 𝐖𝐇𝐄𝐍 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭𝐬: Use conditional logic to tailor query results.
- 𝐃𝐚𝐭𝐞 𝐓𝐢𝐦𝐞 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Master manipulating dates and times for precise analysis.
Next, explore advanced methods to structure and reuse SQL code effectively:
- 𝐂𝐨𝐦𝐦𝐨𝐧 𝐓𝐚𝐛𝐥𝐞 𝐄𝐱𝐩𝐫𝐞𝐬𝐬𝐢𝐨𝐧𝐬 (𝐂𝐓𝐄𝐬): Simplify complex queries into manageable parts to increase the readability.
- 𝐒𝐮𝐛𝐪𝐮𝐞𝐫𝐢𝐞𝐬: Nest queries for more granular data retrieval.
- 𝐓𝐞𝐦𝐩𝐨𝐫𝐚𝐫𝐲 𝐓𝐚𝐛𝐥𝐞𝐬: Create and manipulate temporary data sets for specific tasks.
Then, move on to advanced ones:
- 𝐖𝐢𝐧𝐝𝐨𝐰 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬: Perform advanced calculations over sets of rows with ease.
- 𝐒𝐭𝐨𝐫𝐞𝐝 𝐏𝐫𝐨𝐜𝐞𝐝𝐮𝐫𝐞𝐬: Create reusable SQL routines for streamlined operations.
- 𝐓𝐫𝐢𝐠𝐠𝐞𝐫𝐬: Automate database actions based on specific events.
- 𝐑𝐞𝐜𝐮𝐫𝐬𝐢𝐯𝐞 𝐂𝐓𝐄𝐬: Solve complex problems using recursive queries.
- 𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐚𝐭𝐢𝐨𝐧 𝐨𝐟 𝐐𝐮𝐞𝐫𝐢𝐞𝐬: Techniques to enhance performance and efficiency.
447
10:07
16.02.2025
imageImage preview is unavailable
📖 SQL Short Notes 📝 Beginner To Advance
📖 SQL Short Notes 📝 Beginner To Advance
675
11:19
14.02.2025
Let’s think of SQL as a way to talk to a big toy box full of different toys.
### Imagine This:
1. Toy Box = Database: This is where all your toys (data) are stored.
2. Toys = Tables: Each type of toy is in its own section, like cars in one area and dolls in another.
3. Picking Toys = Queries: When you want to play with certain toys, you ask the toy box (database) to give them to you.
### Basic Commands:
1. SELECT: This is like saying, "Show me my cars!"
- Example:
2. WHERE: This is like saying, "Show me only the red cars!"
- Example:
3. INSERT: This is like adding a new toy to the toy box.
- Example:
4. UPDATE: This is like changing a toy's color.
- Example:
5. DELETE: This is like taking a toy out of the toy box and saying goodbye.
- Example:
### Summary:
- SELECT = Look at your toys.
- WHERE = Choose specific toys.
- INSERT = Add new toys.
- UPDATE = Change your toys.
- DELETE = Remove toys.
That’s it! SQL helps you play with and organize your toys (data) in the best way!
### Imagine This:
1. Toy Box = Database: This is where all your toys (data) are stored.
2. Toys = Tables: Each type of toy is in its own section, like cars in one area and dolls in another.
3. Picking Toys = Queries: When you want to play with certain toys, you ask the toy box (database) to give them to you.
### Basic Commands:
1. SELECT: This is like saying, "Show me my cars!"
- Example:
SELECT * FROM Cars;
means "Show me all the cars!"2. WHERE: This is like saying, "Show me only the red cars!"
- Example:
SELECT * FROM Cars WHERE color = 'red';
3. INSERT: This is like adding a new toy to the toy box.
- Example:
INSERT INTO Cars (color) VALUES ('blue');
means "Add a blue car!"4. UPDATE: This is like changing a toy's color.
- Example:
UPDATE Cars SET color = 'green' WHERE color = 'red';
means "Change all red cars to green."5. DELETE: This is like taking a toy out of the toy box and saying goodbye.
- Example:
DELETE FROM Cars WHERE color = 'blue';
means "Remove the blue car."### Summary:
- SELECT = Look at your toys.
- WHERE = Choose specific toys.
- INSERT = Add new toys.
- UPDATE = Change your toys.
- DELETE = Remove toys.
That’s it! SQL helps you play with and organize your toys (data) in the best way!
663
10:06
14.02.2025
SQL & Pandas INTERVIEW QUESTIONS
1. Find the employee(s) with the second highest salary in the company
SQL:
SELECT employee_id, salary
FROM employees
WHERE salary = (SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1)
Pandas:
second_highest_salary = employees['salary'].nlargest(2).iloc[-1]
second_highest_salary_employees = employees[employees['salary'] == second_highest_salary]
2. Find employees who earn more than the average salary of their department
SQL:
SELECT employee_id, department_id, salary
FROM employees e
WHERE salary > (SELECT AVG(salary)
FROM employees
WHERE department_id = e.department_id)
Pandas:
avg_salary_by_dept = employees.groupby('department_id')['salary'].transform('mean')
higher_than_avg = employees[employees['salary'] > avg_salary_by_dept]
3. Identify the employees who have the longest tenure in each department
SQL:
SELECT department_id, employee_id, hire_date
FROM employees e
WHERE hire_date = (SELECT MIN(hire_date)
FROM employees
WHERE department_id = e.department_id)
Pandas:
longest_tenure = employees.loc[employees.groupby('department_id')['hire_date'].idxmin()]
4. Determine the top N percent of employees based on salary
SQL:
WITH ranked_employees AS (
SELECT employee_id, salary,
PERCENT_RANK() OVER (ORDER BY salary DESC) AS percentile
FROM employees
)
SELECT employee_id, salary
FROM ranked_employees
WHERE percentile <= 0.1 -- Adjust this value for top N percent
Pandas:
top_n_percent = 0.1
salary_threshold = employees['salary'].quantile(1 - top_n_percent)
top_employees = employees[employees['salary'] >= salary_threshold]
1. Find the employee(s) with the second highest salary in the company
SQL:
SELECT employee_id, salary
FROM employees
WHERE salary = (SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1)
Pandas:
second_highest_salary = employees['salary'].nlargest(2).iloc[-1]
second_highest_salary_employees = employees[employees['salary'] == second_highest_salary]
2. Find employees who earn more than the average salary of their department
SQL:
SELECT employee_id, department_id, salary
FROM employees e
WHERE salary > (SELECT AVG(salary)
FROM employees
WHERE department_id = e.department_id)
Pandas:
avg_salary_by_dept = employees.groupby('department_id')['salary'].transform('mean')
higher_than_avg = employees[employees['salary'] > avg_salary_by_dept]
3. Identify the employees who have the longest tenure in each department
SQL:
SELECT department_id, employee_id, hire_date
FROM employees e
WHERE hire_date = (SELECT MIN(hire_date)
FROM employees
WHERE department_id = e.department_id)
Pandas:
longest_tenure = employees.loc[employees.groupby('department_id')['hire_date'].idxmin()]
4. Determine the top N percent of employees based on salary
SQL:
WITH ranked_employees AS (
SELECT employee_id, salary,
PERCENT_RANK() OVER (ORDER BY salary DESC) AS percentile
FROM employees
)
SELECT employee_id, salary
FROM ranked_employees
WHERE percentile <= 0.1 -- Adjust this value for top N percent
Pandas:
top_n_percent = 0.1
salary_threshold = employees['salary'].quantile(1 - top_n_percent)
top_employees = employees[employees['salary'] >= salary_threshold]
740
10:06
13.02.2025
SQL is the most valuable of all data skills.
Here's how I would learn SQL today if I had to start learning from zero:
1) I would leverage my Microsoft Excel knowledge.
Excel is the perfect foundation for learning SQL because it teaches you how to use data tables.
Everything you learn using Excel applies, at a conceptual level, to SQL.
2) Learn how to SELECT data.
Have you ever hidden columns of data in an Excel table?
Conceptually, this is the same as SELECTing the columns you want people to see FROM the table.
As you've probably guessed, SELECT and FROM are the SQL keywords to do this.
See how your Excel knowledge helps?
👇
3) Learn how to filter data.
Have you ever applied a column filter to an Excel table?
You're showing only the rows WHERE some logical condition is true.
For example, filtering rows for a specific geography.
In SQL, you use WHERE to define your filters.
Excel knowledge keeps helping...
4) Learn to pivot data.
Imagine you've created a PivotTable in Excel.
You've selected 2 columns for the rows to calculate the AVERAGE of another column.
You ask Excel to GROUP BY the 2 columns before calculating the AVERAGEs.
GROUP BY and AVERAGE are SQL keywords.
5) Learn to combine tables.
If you've ever used VLOOKUP/XLOOKUP to populate a column in an Excel table,
You've JOINed data stored in multiple tables.
Conceptually, the process works the same in SQL using what are known as JOINs.
6) Expand your knowledge.
SQL is mighty.
Many other SQL capabilities will benefit you.
For example, SQL's window functions.
Join for more: https://t.me/mysqldata
Here's how I would learn SQL today if I had to start learning from zero:
1) I would leverage my Microsoft Excel knowledge.
Excel is the perfect foundation for learning SQL because it teaches you how to use data tables.
Everything you learn using Excel applies, at a conceptual level, to SQL.
2) Learn how to SELECT data.
Have you ever hidden columns of data in an Excel table?
Conceptually, this is the same as SELECTing the columns you want people to see FROM the table.
As you've probably guessed, SELECT and FROM are the SQL keywords to do this.
See how your Excel knowledge helps?
👇
3) Learn how to filter data.
Have you ever applied a column filter to an Excel table?
You're showing only the rows WHERE some logical condition is true.
For example, filtering rows for a specific geography.
In SQL, you use WHERE to define your filters.
Excel knowledge keeps helping...
4) Learn to pivot data.
Imagine you've created a PivotTable in Excel.
You've selected 2 columns for the rows to calculate the AVERAGE of another column.
You ask Excel to GROUP BY the 2 columns before calculating the AVERAGEs.
GROUP BY and AVERAGE are SQL keywords.
5) Learn to combine tables.
If you've ever used VLOOKUP/XLOOKUP to populate a column in an Excel table,
You've JOINed data stored in multiple tables.
Conceptually, the process works the same in SQL using what are known as JOINs.
6) Expand your knowledge.
SQL is mighty.
Many other SQL capabilities will benefit you.
For example, SQL's window functions.
Join for more: https://t.me/mysqldata
713
16:39
12.02.2025
close
Reviews channel
No reviews
New items
Channel statistics
Rating
7.1
Rating reviews
0.0
Сhannel Rating
0
Followers:
1.8K
APV
lock_outline
ER
20.0%
Posts per day:
1.0
CPM
lock_outlineSelected
0
channels for:$0.00
Followers:
0
Views:
lock_outline
Add to CartBuy for:$0.00
Комментарий