SQL | Data Analytics
Ir al canal en Telegram
SQL, Big Query, Looker and DBT for Data Analytics. https://medium.com/@khavanski
Mostrar más1 858
Suscriptores
Sin datos24 horas
+27 días
+730 días
Archivo de publicaciones
1 858
85 career-focused Data and AI courses for FREE until Nov 21st https://365datascience.com/courses/
1 858
🎄 Christmas SQL Challenge! 🎄
Ready to sharpen your SQL skills with a festive twist? Dive into our holiday-themed SQL marathon, running from December 1st to Christmas! 🎅
What to Expect:
📧 Daily Challenges — receive a new SQL challenge in your inbox every morning, each with a Christmas theme!
🎁 Holiday Vibes — enjoy fun, festive challenges to make learning SQL even more exciting.
💾 Practice Database Dump — access a full database dump with holiday-themed data to work on real-world tasks.
📚 Step-by-Step Instructions — each challenge comes with clear guidance to help you succeed from start to finish.
How to Join:
Sign up now — register today to reserve your spot!
Get ready for December 1st — your first challenge will arrive that morning.
Solve daily tasks — boost your SQL skills and have a holly-jolly time!
Make this December a season of growth and accomplishment with SQL! 🎄
1 858
How do you find the total number of records in a table named employees?
1 858
Mastering the `EXCEPT` Clause in #SQL: Simplify Your SELECT Statements
When working with SQL, especially with tables that have dozens or even hundreds of columns, listing every column in a
SELECT query can be a real pain, especially when you only need to exclude a few. Enter the EXCEPT clause—an often overlooked feature that can simplify your queries and make your code cleaner.
### What is EXCEPT in SQL?
The EXCEPT clause allows you to select all columns from a table while excluding specific ones. Think of it as an easy way to grab most columns from a table without having to specify each one individually. It’s particularly useful for ad-hoc analysis and MVPs, especially in environments like Databricks, Snowflake, and BigQuery where this syntax is supported.
### Why Use EXCEPT?
1. Saves Time: Instead of listing dozens of columns, you can exclude the few you don’t need.
2. Reduces Errors: Manually listing many columns can lead to typos and missed updates.
3. Improves Readability: With EXCEPT, your queries are more concise and easier to maintain.
### Syntax and Example
Here’s how to use EXCEPT in a SELECT statement:
SELECT * EXCEPT (column1, column2, ...)
FROM table_name;
#### Example Use Case
Imagine you have a table called orders with 50 columns, and you only want to exclude two system-generated columns, created_at and updated_at. Without EXCEPT, you would have to list the 48 remaining columns manually. With EXCEPT, you can simplify your query like this:
SELECT * EXCEPT (created_at, updated_at)
FROM orders;
### When to Use EXCEPT
While EXCEPT is convenient, it’s not always recommended for production queries because:
- SELECT * can lead to issues if the table schema changes over time.
- Some database platforms don’t support EXCEPT in SELECT (check your database documentation).
However, it’s an excellent tool for quick data exploration, prototyping, and working with wide tables.
### Final Thoughts
The EXCEPT clause might not be standard ANSI SQL, but it’s a powerful tool available in several modern SQL platforms. Next time you’re faced with a wide table and need to exclude a few columns, give EXCEPT a try—it just might save you time and make your code cleaner!1 858
✨The STAR method is a powerful technique used to answer behavioral interview questions effectively.
It helps structure responses by focusing on **S**ituation, **T**ask, **A**ction, and **R**esult. For analytics professionals, using the STAR method ensures that you demonstrate your problem-solving abilities, technical skills, and business acumen in a clear and concise way.
Here’s how the STAR method works, tailored for an analytics interview:
📍 1. Situation
Describe the context or challenge you faced. For analysts, this might be related to data challenges, business processes, or system inefficiencies. Be specific about the setting, whether it was a project, a recurring task, or a special initiative.
Example: “At my previous role as a data analyst at XYZ Company, we were experiencing a high churn rate among our subscription customers. This was a critical issue because it directly impacted revenue.”*
📍 2. Task
Explain the responsibilities you had or the goals you needed to achieve in that situation. In analytics, this usually revolves around diagnosing the problem, designing experiments, or conducting data analysis.
Example: “I was tasked with identifying the factors contributing to customer churn and providing actionable insights to the marketing team to help them improve retention.”*
📍 3. Action
Detail the specific actions you took to address the problem. Be sure to mention any tools, software, or methodologies you used (e.g., SQL, Python, data #visualization tools, #statistical #models). This is your opportunity to showcase your technical expertise and approach to problem-solving.
Example: “I collected and analyzed customer data using #SQL to extract key trends. I then used #Python for data cleaning and statistical analysis, focusing on engagement metrics, product usage patterns, and customer feedback. I also collaborated with the marketing and product teams to understand business priorities.”*
📍 4. Result
Highlight the outcome of your actions, especially any measurable impact. Quantify your results if possible, as this demonstrates your effectiveness as an analyst. Show how your analysis directly influenced business decisions or outcomes.
Example: “As a result of my analysis, we discovered that customers were disengaging due to a lack of certain product features. My insights led to a targeted marketing campaign and product improvements, reducing churn by 15% over the next quarter.”*
Example STAR Answer for an Analytics Interview Question:
Question: *"Tell me about a time you used data to solve a business problem."*
Answer (STAR format):
🔻*S*: “At my previous company, our sales team was struggling with inconsistent performance, and management wasn’t sure which factors were driving the variance.”
🔻*T*: “I was assigned the task of conducting a detailed analysis to identify key drivers of sales performance and propose data-driven recommendations.”
🔻*A*: “I began by collecting sales data over the past year and segmented it by region, product line, and sales representative. I then used Python for #statistical #analysis and developed a regression model to determine the key factors influencing sales outcomes. I also visualized the data using #Tableau to present the findings to non-technical stakeholders.”
🔻*R*: “The analysis revealed that product mix and regional seasonality were significant contributors to the variability. Based on my findings, the company adjusted their sales strategy, leading to a 20% increase in sales efficiency in the next quarter.”
1 858
Premios del sorteo
1 suscripciones Premium de Telegram por 3 meses
Fecha de finalización
1 858
If you have premium telegram, you can support us.
Thank you and good weekend!😍
https://t.me/boost/sql_and_dbt
1 858
Understanding Window Functions in SQL: A Game Changer for Data Analysis
If you're into data analysis with SQL, you've probably encountered situations where you need to perform calculations across a set of table rows. This is where window functions come into play, offering a powerful way to solve complex tasks that would otherwise require multiple subqueries or joins.
📚 What Are Window Functions?
Window functions allow you to perform calculations across a set of rows that are somehow related to the current row. Unlike aggregate functions (e.g.,
SUM(), `AVG()`), which return a single result for a group of rows, window functions maintain the individual row values while still performing calculations on a "window" of rows.
🔻 Key Components
1. OVER() Clause: This defines the "window" or the set of rows to operate on. It can include:
- PARTITION BY: Similar to GROUP BY, it divides the result set into partitions.
- ORDER BY: Specifies the order in which rows should be processed.
- Frame Specification: Defines the range of rows for the calculation (e.g., `ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING`).
2. Common Window Functions:
- ROW_NUMBER(): Assigns a unique sequential number to each row in the partition.
- RANK() and DENSE_RANK(): Provide ranking for rows based on the specified order.
- LAG() and LEAD(): Access data from previous or subsequent rows.
- SUM(), AVG(), MIN(), MAX(): Perform cumulative aggregations.
📍 Why Use Window Functions?
- Data Ranking and Pagination: Easily rank results or implement pagination in your queries.
- Moving Averages and Running Totals: Calculate cumulative sums or rolling averages without complex joins.
- Comparisons Across Rows: Compare current row values with previous or next row values (useful for trend analysis).
📊 Example Use Case
SELECT
employee_id,
department,
salary,
RANK() OVER(PARTITION BY department ORDER BY salary DESC) AS salary_rank
FROM
employees;
In this example, we rank employees within each department based on their salaries. The PARTITION BY clause creates partitions for each department, while the ORDER BY clause sorts the salaries in descending order.
💪 Take Your SQL Skills to the Next Level
Window functions are essential for advanced SQL querying. Mastering them can significantly enhance your ability to manipulate and analyze data directly within the database. So next time you find yourself writing nested subqueries, consider using window functions instead!
Stay tuned for more SQL tips, and happy querying!
#SQL #DataAnalysis #WindowFunctions #Database #DataScience1 858
🔥 Working with Intersect and Except in SQL
When dealing with datasets in SQL, you often need to find common records in two tables or determine the differences between them. For these purposes, SQL provides two useful operators:
INTERSECT and EXCEPT. Let’s take a closer look at how they work.
🔻 The INTERSECT Operator
The INTERSECT operator is used to find rows that are present in both queries. It works like the intersection of sets in mathematics, returning only those records that exist in both datasets.
Example:
SELECT column1, column2
FROM table1
INTERSECT
SELECT column1, column2
FROM table2;
This will return rows that appear in both table1 and table2.
Key Points:
- The INTERSECT operator automatically removes duplicate rows from the result.
- The selected columns must have compatible data types.
🔻 The EXCEPT Operator
The EXCEPT operator is used to find rows that are present in the first query but not in the second. This is similar to the difference between sets, returning only those records that exist in the first dataset but are missing from the second.
Example:
SELECT column1, column2
FROM table1
EXCEPT
SELECT column1, column2
FROM table2;
Here, the result will include rows that are in table1 but not in table2.
Key Points:
- The EXCEPT operator also removes duplicate rows from the result.
- As with INTERSECT, the columns must have compatible data types.
📊 What’s the Difference Between UNION, INTERSECT, and EXCEPT?
- UNION combines all rows from both queries, excluding duplicates.
- INTERSECT returns only the rows present in both queries.
- EXCEPT returns rows from the first query that are not found in the second.
📌 Real-Life Examples
1. Finding common customers. Use INTERSECT to identify customers who have made purchases both online and in physical stores.
2. Determining unique products. Use EXCEPT to find products that are sold in one store but not in another.
By using INTERSECT and EXCEPT, you can simplify data analysis and work more flexibly with sets, making it easier to solve tasks related to finding intersections and differences between datasets.
Happy querying!1 858
✅ All courses are FREE on Maven Analytics right now.
You heard me. ALL of them.
Our Open Campus event goes live today. It's one of the best opportunities we provide to the community all year.
Here's what you can expect from now until 10/31:
1. Unlimited access to the entire course library.
2. Tons of live events from seasoned experts.
3. Friendly competitions and big prizes.
It's a great chance to get to know the platform.
If I were learning data skills for the first time, you better believe I'd be grinding for the next 10 days.
These are world-class courses, completely free.
👇Read more about it and register here:
https://mavenanalytics.io/open-campus
#sql #analytics
1 858
✅SQL Tutorial for Beginners [Full Course]
Learn SQL with #MySQL from scratch! 📚 This beginner-friendly tutorial covers #SQL essentials for working with databases.
https://www.youtube.com/watch?v=7S_tz1z_5bA
1 858
✍ Mastering Conditional Aggregation in SQL: A Quick Guide
Conditional aggregation is a powerful SQL technique that lets you perform aggregate functions based on specific conditions. This approach allows you to calculate values more selectively, adding flexibility to your data analysis. Let's break it down with examples to see how you can leverage this method in SQL.
📍 What Is Conditional Aggregation?
Standard aggregation functions like
SUM(), COUNT(), and AVG() summarize data across rows without any distinction. However, there are times when you only want to aggregate data that meets certain conditions. Conditional aggregation helps with that by applying aggregate functions based on specific criteria.
📍 Example: Sales Data Analysis
Let’s say you have a table called `sales` with information on store sales: store ID (`stor_id`), quantity sold (`qty`), and order date (`ord_date`). You want to calculate total sales for each store in the year 1993.
📍Example 1: Total Sales in 1993
SELECT stor_id,
SUM(CASE WHEN YEAR(ord_date) = 1993 THEN qty ELSE 0 END) AS total_sales
FROM sales
GROUP BY stor_id
ORDER BY total_sales DESC;
Here, the SUM() function aggregates only the sales data from 1993 by using a CASE statement. Rows from other years contribute 0 to the total.
#### Example 2: Average Monthly Sales in 1993
SELECT stor_id, MONTH(ord_date) AS month,
AVG(CASE WHEN YEAR(ord_date) = 1993 THEN qty ELSE 0 END) AS avg_sales
FROM sales
WHERE YEAR(ord_date) = 1993
GROUP BY stor_id, month
ORDER BY stor_id;
In this query, we calculate the average monthly sales for each store in 1993. The AVG() function works conditionally by including only rows from that year. We use WHERE to filter out irrelevant data, focusing on the year 1993.
📍 Example 3: Categorizing Sales
SELECT stor_id,
SUM(CASE WHEN YEAR(ord_date) = 1993 THEN qty ELSE 0 END) AS total_sales_1993,
CASE
WHEN SUM(CASE WHEN YEAR(ord_date) = 1993 THEN qty ELSE 0 END) < 1000 THEN 'Low Sales'
WHEN SUM(CASE WHEN YEAR(ord_date) = 1993 THEN qty ELSE 0 END) BETWEEN 1000 AND 5000 THEN 'Medium Sales'
ELSE 'High Sales'
END AS sales_category
FROM sales
GROUP BY stor_id;
This query goes one step further by creating a new column that categorizes stores based on their total sales in 1993. We use a CASE statement to label the sales as 'Low', 'Medium', or 'High' based on specific thresholds.
📍 Key Takeaways
- Conditional aggregation allows you to apply functions like SUM(), AVG(), and others based on specific criteria.
- Using CASE statements inside aggregate functions gives you control over which rows contribute to the result.
- Conditional aggregation is useful for more tailored insights, such as filtering by specific timeframes, creating categories, and more.
Incorporating these techniques into your #SQL queries enhances your ability to extract meaningful, granular insights from your data. Start experimenting with conditional aggregation to take your SQL analysis to the next level!1 858
🔻 In this article, she will cover the foundational knowledge about data visualization and this help you avoid silly mistakes and set high standards on data communication with your stakeholders.
📍Link - https://blog.surfalytics.com/p/just-enough-data-viz-for-data-professionals?triedRedirect=true
#dataviz #dataanalytics
1 858
Mini Data Engineering Project: Monitor Apache Airflow with #Airbyte, Snowflake, and Superset
In this video, you will build a dashboard to monitor your Airflow instance using different metrics.
🔥You will learn:
✅ Using the Airflow REST API to build metrics
✅ Extracting data from your Airflow instance using Airbyte
✅ Creating an Airflow connector with the Airbyte AI Builder
✅ Storing data of your Airflow instance into Snowflake with Airbyte
✅ Defining metrics to monitor with #Superset
✅ Running Airflow in the cloud with Astronomer
and more!
Enjoy ❤️
https://www.youtube.com/watch?v=x7oRfH4ig54

