{"id":112883,"date":"2025-10-31T11:30:37","date_gmt":"2025-10-31T06:00:37","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/"},"modified":"2025-10-31T10:37:15","modified_gmt":"2025-10-31T05:07:15","slug":"sql-for-data-analysis","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/","title":{"rendered":"SQL for Data Analysis Tutorial"},"content":{"rendered":"\n<p>Every business relies on information derived from customer transactions, product performance, and other data. However, when this information scales to millions or billions of records, extracting meaningful insights becomes a significant challenge.<\/p>\n\n\n\n<p>Excel or Python can become slow, crash, or require excessive manual effort to uncover even simple insights:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Which customers are bringing the most revenue?<\/li>\n\n\n\n<li>What is performing better this quarter?<\/li>\n<\/ul>\n\n\n\n<p>This is where SQL (Structured Query Language) is useful.<\/p>\n\n\n\n<p>In this tutorial, you will get to know how SQL can assist you in organizing, filtering, and analyzing large volumes of data easily to transform raw data into information that can be used to make decisions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-sql\">What is SQL?<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/\">SQL<\/a> (Structured Query Language) is a standardized <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-are-the-best-programming-languages-to-learn\/\">programming language<\/a> designed to work with relational databases. It plays a vital role in managing and analyzing large volumes of data efficiently. SQL is widely used for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data Retrieval<\/strong> \u2013 extracting specific information from vast datasets.<\/li>\n\n\n\n<li><strong>Data Storage<\/strong> \u2013 organizing and saving data systematically in tables.<\/li>\n\n\n\n<li><strong>Data Management<\/strong> \u2013 maintaining and structuring databases for optimal performance.<\/li>\n\n\n\n<li><strong>Data Analysis<\/strong> \u2013 generating insights and reports from raw data.<\/li>\n<\/ul>\n\n\n\n<p>It also enables users to perform essential operations such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data Creation<\/li>\n\n\n\n<li>Data Updating<\/li>\n\n\n\n<li>Data Deletion<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"key-functions-of-sql-for-data-analysis\">Key Functions of SQL for Data Analysis<\/h2>\n\n\n\n<p><strong>1. Query Data Efficiently:<\/strong> SQL lets you pull exactly the data you need using commands like <code>SELECT<\/code> and <code>FROM<\/code>.<\/p>\n\n\n\n<p><strong>2. Filter &amp; Focus:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Narrow down datasets with <code>WHERE<\/code>, <code>AND<\/code>, <code>OR<\/code>, &amp; other conditions.<\/li>\n\n\n\n<li>Focus on only the relevant rows instead of handling entire tables manually.<\/li>\n<\/ul>\n\n\n\n<p><strong>3. Aggregate &amp; Summarize:<\/strong> Use <code>GROUP BY<\/code>, <code>COUNT()<\/code>, <code>SUM()<\/code>, <code>AVG()<\/code> to summarize data.<\/p>\n\n\n\n<p><strong>4. Combine Multiple Tables:<\/strong> <code>JOIN<\/code> tables to create a unified view of related data.<\/p>\n\n\n\n<p><strong>5. Sort &amp; Limit Results:<\/strong> Organize data with <code>ORDER BY<\/code> &amp; restrict output using <code>LIMIT<\/code> for quick analysis.<\/p>\n\n\n\n<p>SQL is the analyst\u2019s toolkit inside the database; it lets you answer business questions quickly, safely, and efficiently.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-data-analytics-in-sql\" class=\"courses-cta-title-link\">SQL Data Analytics Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn SQL for data analytics in this course designed to help you turn raw data into clear insights. Master essential tools and techniques to make smarter, data-driven business choices.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>39 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-data-analytics-in-sql\" class=\"courses-cta-button\">\n                Learn SQL for Data Analysis\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"core-sql-commands-for-data-analysis\">Core SQL Commands for Data Analysis<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-your-first-queries-select-and-from\">1. Your First Queries - SELECT and FROM<\/h3>\n\n\n\n<p>When working with a database, your primary objective is to find answers to your questions. SQL provides two essential commands to do this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SELECT<\/strong> \u2013 tells SQL what information you want to see.<\/li>\n\n\n\n<li><strong>FROM<\/strong> \u2013 tells SQL where to find it (the table).<\/li>\n<\/ul>\n\n\n\n<p>These <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">commands<\/a> are the foundation for every SQL query you\u2019ll write. Let\u2019s understand this with a step-by-step using a <strong>Sample Dataset \u2013 Products<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>ProductID<\/th><th>ProductName<\/th><th>Category<\/th><th>Price<\/th><th>Stock<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Laptop<\/td><td>Electronics<\/td><td>800<\/td><td>50<\/td><\/tr><tr><td>2<\/td><td>Headphones<\/td><td>Electronics<\/td><td>50<\/td><td>200<\/td><\/tr><tr><td>3<\/td><td>Chair<\/td><td>Furniture<\/td><td>120<\/td><td>150<\/td><\/tr><tr><td>4<\/td><td>Desk<\/td><td>Furniture<\/td><td>300<\/td><td>100<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-1-seeing-everything-in-the-table\">Query 1 - Seeing Everything in the Table<\/h4>\n\n\n\n<p>Before starting an analysis, it's useful to preview the entire table to understand its structure. To do this, you need to write:<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM Products;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The asterisk (<code>*<\/code>) means \u201call columns.\u201d<\/li>\n\n\n\n<li>This query retrieves every column &amp; every row from the table, providing you with an overview of your data before narrowing it down.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>ProductID<\/th><th>ProductName<\/th><th>Category<\/th><th>Price<\/th><th>Stock<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Laptop<\/td><td>Electronics<\/td><td>800<\/td><td>50<\/td><\/tr><tr><td>2<\/td><td>Headphones<\/td><td>Electronics<\/td><td>50<\/td><td>200<\/td><\/tr><tr><td>3<\/td><td>Chair<\/td><td>Furniture<\/td><td>120<\/td><td>150<\/td><\/tr><tr><td>4<\/td><td>Desk<\/td><td>Furniture<\/td><td>300<\/td><td>100<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-2-selecting-specific-columns\">Query 2 \u2013 Selecting Specific Columns<\/h4>\n\n\n\n<p>Once you know what's in the table, you can fetch specific information, such as just the product names and their prices. To get this, the SQL query would be:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT ProductName, Price \nFROM Products;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>List the exact column names you want after <code>SELECT<\/code>: <code>ProductName<\/code>, <code>Price<\/code><\/li>\n\n\n\n<li>Separate multiple columns with a comma.<\/li>\n<\/ul>\n\n\n\n<p>This approach retrieves only the data you need, rather than the entire table.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>ProductName<\/th><th>Price<\/th><\/tr><\/thead><tbody><tr><td>Laptop<\/td><td>800<\/td><\/tr><tr><td>Headphones<\/td><td>50<\/td><\/tr><tr><td>Chair<\/td><td>120<\/td><\/tr><tr><td>Desk<\/td><td>300<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-filtering-your-data-where\">2. Filtering Your Data \u2013 WHERE<\/h3>\n\n\n\n<p>Using the <code>WHERE<\/code> clause allows you to retrieve only those rows that meet specific conditions.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"common-operators\">Common Operators<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operator<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>=<\/code><\/td><td>Equals<\/td><\/tr><tr><td><code>!=<\/code><\/td><td>Not equals<\/td><\/tr><tr><td><code>&gt;, &lt;<\/code><\/td><td>Greater than \/ Less than<\/td><\/tr><tr><td><code>&gt;=<\/code><\/td><td>Greater than or equal to<\/td><\/tr><tr><td><code>&lt;=<\/code><\/td><td>Less than or equal to<\/td><\/tr><tr><td><code>AND<\/code><\/td><td>Both conditions must be true<\/td><\/tr><tr><td><code>OR<\/code><\/td><td>Either condition can be true<\/td><\/tr><tr><td><code>IN<\/code><\/td><td>Matches any value in a list<\/td><\/tr><tr><td><code>LIKE<\/code><\/td><td>Pattern matching (e.g., <code>LIKE 'A%'<\/code> for names starting with A)<\/td><\/tr><tr><td><code>BETWEEN<\/code><\/td><td>For a range of numbers or dates<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"step-1-sample-dataset-customers\">Step 1: Sample Dataset \u2013 Customers<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerID<\/th><th>CustomerName<\/th><th>Country<\/th><th>Age<\/th><th>PurchaseAmount<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Alice Brown<\/td><td>USA<\/td><td>28<\/td><td>500<\/td><\/tr><tr><td>2<\/td><td>John Miller<\/td><td>Canada<\/td><td>35<\/td><td>1200<\/td><\/tr><tr><td>3<\/td><td>Priya Sharma<\/td><td>India<\/td><td>24<\/td><td>700<\/td><\/tr><tr><td>4<\/td><td>Robert Chen<\/td><td>China<\/td><td>40<\/td><td>300<\/td><\/tr><tr><td>5<\/td><td>Maria Lopez<\/td><td>Mexico<\/td><td>30<\/td><td>1500<\/td><\/tr><tr><td>6<\/td><td>David Wilson<\/td><td>USA<\/td><td>22<\/td><td>250<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-1-customers-who-spent-more-than-700\">Query 1 \u2013 Customers Who Spent More Than $700<\/h4>\n\n\n\n<p>We can filter the dataset to focus on customers who spent over $700 for targeted marketing as well as analysis.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT CustomerName, Country, PurchaseAmount\nFROM Customers\nWHERE PurchaseAmount &gt; 700;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>WHERE<\/code> clause filters rows based on a condition.<\/li>\n\n\n\n<li>Here, it selects only customers whose <code>PurchaseAmount<\/code> is greater than 700.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>Country<\/th><th>PurchaseAmount<\/th><\/tr><\/thead><tbody><tr><td>John Miller<\/td><td>Canada<\/td><td>1200<\/td><\/tr><tr><td>Maria Lopez<\/td><td>Mexico<\/td><td>1500<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-2-customers-from-the-usa-under-30-years-old\">Query 2 \u2013 Customers from the USA Under 30 Years Old<\/h4>\n\n\n\n<p>To analyze a specific demographic, we can find customers who are both from the USA &amp; under 30 years old. This helps understand patterns in younger local customers\u2019 behavior.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT CustomerName, Country, Age\nFROM Customers\nWHERE Country = &#039;USA&#039; AND Age &amp;lt; 30;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>AND<\/code> ensures both conditions are true.<\/li>\n\n\n\n<li>Only customers who meet both criteria from the USA &amp; younger than 30 are returned.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>Country<\/th><th>Age<\/th><\/tr><\/thead><tbody><tr><td>Alice Brown<\/td><td>USA<\/td><td>28<\/td><\/tr><tr><td>David Wilson<\/td><td>USA<\/td><td>22<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-3-customers-from-india-or-mexico\">Query 3 \u2013 Customers from India or Mexico<\/h4>\n\n\n\n<p>To retrieve customers from either India or Mexico, to include multiple countries in our analysis &amp; enable regional comparisons or targeted campaigns.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT CustomerName, Country\nFROM Customers\nWHERE Country = &#039;India&#039; OR Country = &#039;Mexico&#039;;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>OR<\/code> allows either condition to be true.<\/li>\n\n\n\n<li>Returns customers from India or Mexico, covering multiple geographic locations.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>Country<\/th><\/tr><\/thead><tbody><tr><td>Priya Sharma<\/td><td>India<\/td><\/tr><tr><td>Maria Lopez<\/td><td>Mexico<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-summarizing-your-data-group-by-and-aggregates\">3. Summarizing Your Data \u2013 GROUP BY and Aggregates<\/h3>\n\n\n\n<p>Instead of reviewing every row in large datasets, SQL\u2019s aggregate functions &amp; <code>GROUP BY<\/code> let you summarize data to answer your key business questions.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"key-aggregate-functions\">Key Aggregate Functions<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Function \/ Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>COUNT()<\/code><\/td><td>Counts the number of rows.<\/td><\/tr><tr><td><code>SUM()<\/code><\/td><td>Adds up all values in a column.<\/td><\/tr><tr><td><code>AVG()<\/code><\/td><td>Calculates the average of values.<\/td><\/tr><tr><td><code>MIN() \/ MAX()<\/code><\/td><td>Finds the minimum or maximum value.<\/td><\/tr><tr><td><code>GROUP BY<\/code><\/td><td>Groups rows by a column so aggregate functions can be applied to each group.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"important-rule\">Important Rule<\/h4>\n\n\n\n<p>Aggregate functions like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SUM<\/code>,<\/li>\n\n\n\n<li><code>AVG<\/code>,<\/li>\n\n\n\n<li><code>MIN<\/code>,<\/li>\n\n\n\n<li><code>MAX<\/code>,<\/li>\n\n\n\n<li><code>COUNT(column_name)<\/code><\/li>\n<\/ul>\n\n\n\n<p>All ignore <code>NULL<\/code> values. The main exception is <code>COUNT(*)<\/code>, which counts every row in the group, regardless of whether individual columns contain <code>NULL<\/code>s.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"a-quick-note-on-renaming-columns-with-as\">A Quick Note on Renaming Columns with AS<\/h4>\n\n\n\n<p>In the following sections, you will see the keyword <code>AS<\/code>. This is the alias command.<\/p>\n\n\n\n<p>Its job is simple: to rename a column or the result of a calculation in your output. This is used for two main reasons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Readability:<\/strong><br>It makes your report headers much cleaner (e.g., <code>VisitCount<\/code> is easier to read than <code>COUNT(*)<\/code>).<\/li>\n\n\n\n<li><strong>Sorting:<\/strong><br>It gives you a simple name to use in your <code>ORDER BY<\/code> clause.<\/li>\n<\/ul>\n\n\n\n<p><strong>How to use it?<\/strong><\/p>\n\n\n\n<p>You place <code>AS<\/code> immediately after the column or function you want to rename, followed by the new name you want to give it.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"step-1-sample-dataset-user_interactions\">Step 1: Sample Dataset \u2013 user_interactions<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>UserID<\/th><th>Action<\/th><th>ContentID<\/th><th>Timestamp<\/th><th>Duration<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Watch<\/td><td>101<\/td><td>2024-03-05 10:22:45<\/td><td>5<\/td><\/tr><tr><td>2<\/td><td>Like<\/td><td>102<\/td><td>2024-03-05 11:45:12<\/td><td>NULL<\/td><\/tr><tr><td>3<\/td><td>Subscribe<\/td><td>NULL<\/td><td>2024-03-05 13:34:21<\/td><td>NULL<\/td><\/tr><tr><td>4<\/td><td>Watch<\/td><td>103<\/td><td>2024-03-05 15:12:33<\/td><td>8<\/td><\/tr><tr><td>5<\/td><td>Like<\/td><td>104<\/td><td>2024-03-05 17:45:21<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Note:<\/strong> The <code>Duration<\/code> column represents minutes watched &amp; is used to demonstrate:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SUM<\/code><\/li>\n\n\n\n<li><code>AVG<\/code><\/li>\n\n\n\n<li><code>MIN<\/code><\/li>\n\n\n\n<li><code>MAX<\/code> functions.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-1-counting-actions\">Query 1 \u2013 Counting Actions<\/h4>\n\n\n\n<p>To understand overall user engagement, it\u2019s useful to know how frequently each type of action occurs.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Action, COUNT(*) AS ActionCount\nFROM user_interactions\nGROUP BY Action;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>COUNT(*) AS ActionCount<\/code> counts the total number of rows for each group &amp; renames the new column to <code>ActionCount<\/code>.<\/li>\n\n\n\n<li><code>GROUP BY Action<\/code> groups all rows by the <code>Action<\/code> column ('Watch', 'Like', 'Subscribe'), so the count is calculated for each unique action.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Action<\/th><th>ActionCount<\/th><\/tr><\/thead><tbody><tr><td>Watch<\/td><td>2<\/td><\/tr><tr><td>Like<\/td><td>2<\/td><\/tr><tr><td>Subscribe<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-2-summarizing-durations-by-action-sum-avg-min-max\">Query 2 \u2013Summarizing Durations by Action (SUM, AVG, MIN, MAX)<\/h4>\n\n\n\n<p>To understand engagement across all action types, we can calculate the:<br>Total<br>Average<br>Shortest &amp; longest<br>durations for each action simultaneously.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n\u00a0\u00a0Action,\n\u00a0\u00a0SUM(Duration) AS TotalDuration,\n\u00a0\u00a0AVG(Duration) AS AvgDuration,\n\u00a0\u00a0MIN(Duration) AS MinDuration,\n\u00a0\u00a0MAX(Duration) AS MaxDuration\nFROM user_interactions\nGROUP BY Action;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>GROUP BY Action<\/code> first splits the table into three groups:\n<ul class=\"wp-block-list\">\n<li>'Watch'<\/li>\n\n\n\n<li>'Like'<\/li>\n\n\n\n<li>'Subscribe'<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>The aggregate functions (<code>SUM<\/code>, <code>AVG<\/code>, <code>MIN<\/code>, <code>MAX<\/code>) are then applied to each group separately.<\/li>\n\n\n\n<li><strong>'Watch' Group:<\/strong> The insights are\n<ul class=\"wp-block-list\">\n<li><code>SUM(5, 8)<\/code> is 13.<\/li>\n\n\n\n<li><code>AVG(5, 8)<\/code> is 6.5.<\/li>\n\n\n\n<li><code>MIN<\/code> is 5,<\/li>\n\n\n\n<li><code>MAX<\/code> is 8.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>'Like' &amp; 'Subscribe' Groups:<\/strong> Since their <code>Duration<\/code> values are all <code>NULL<\/code>, the functions ignore them, resulting in <code>NULL<\/code> for the totals.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Action<\/th><th>TotalDuration<\/th><th>AvgDuration<\/th><th>MinDuration<\/th><th>MaxDuration<\/th><\/tr><\/thead><tbody><tr><td>Watch<\/td><td>13<\/td><td>6.5<\/td><td>5<\/td><td>8<\/td><\/tr><tr><td>Like<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><\/tr><tr><td>Subscribe<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-sorting-results-with-order-by-and-limit\">4. Sorting Results With ORDER BY and LIMIT<\/h3>\n\n\n\n<p>Using <code>ORDER BY<\/code> with <code>LIMIT<\/code>, you can rank your results and focus on the top entries.<br>This allows analysts to quickly identify the most important insights, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Busiest Departments<\/li>\n\n\n\n<li>Top-Performing Products<\/li>\n\n\n\n<li>Highest-Value Customers<\/li>\n<\/ul>\n\n\n\n<p>without having to manually sort or sift through all the data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"key-points\">Key Points<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ORDER BY<\/code> \u2013 sorts results by one or more columns.<\/li>\n\n\n\n<li><code>ASC<\/code> (Ascending, A-Z, 1-10) \u2013 default order.<\/li>\n\n\n\n<li><code>DESC<\/code> (Descending, Z-A, 10-1) \u2013 reverse order.<\/li>\n\n\n\n<li><code>LIMIT<\/code> \u2013 restricts the output to a specific number of rows.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"step-1-sample-dataset-patientvisits\">Step 1: Sample Dataset \u2013 PatientVisits<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>VisitID<\/th><th>PatientID<\/th><th>VisitDate<\/th><th>Department<\/th><th>Reason<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>P1001<\/td><td>2024-03-01<\/td><td>Cardiology<\/td><td>Routine Checkup<\/td><\/tr><tr><td>2<\/td><td>P1002<\/td><td>2024-03-01<\/td><td>General Medicine<\/td><td>Flu Symptoms<\/td><\/tr><tr><td>3<\/td><td>P1003<\/td><td>2024-03-02<\/td><td>Orthopedics<\/td><td>Knee Pain<\/td><\/tr><tr><td>4<\/td><td>P1004<\/td><td>2024-03-02<\/td><td>Neurology<\/td><td>Migraine<\/td><\/tr><tr><td>5<\/td><td>P1001<\/td><td>2024-03-03<\/td><td>Cardiology<\/td><td>Follow-up Visit<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-finding-the-busiest-departments\">Query \u2013 Finding the Busiest Departments<\/h4>\n\n\n\n<p>To determine which departments are handling the most patient visits, we can count the number of visits per department &amp; sort the results.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Department, COUNT(*) AS VisitCount\nFROM PatientVisits\nGROUP BY Department\nORDER BY VisitCount DESC;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT Department, COUNT(*) AS VisitCount<\/code> \u2013 Shows the department and renames the count column to \"VisitCount\".<\/li>\n\n\n\n<li><code>FROM PatientVisits<\/code> \u2013 Uses data from the PatientVisits table.<\/li>\n\n\n\n<li><code>GROUP BY Department<\/code> \u2013 Groups all visits by department before counting.<\/li>\n\n\n\n<li><code>ORDER BY VisitCount DESC<\/code> \u2013 Sorts the results by our new <code>VisitCount<\/code> column in descending order, so the busiest department appears first.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Department<\/th><th>VisitCount<\/th><\/tr><\/thead><tbody><tr><td>Cardiology<\/td><td>2<\/td><\/tr><tr><td>General Medicine<\/td><td>1<\/td><\/tr><tr><td>Orthopedics<\/td><td>1<\/td><\/tr><tr><td>Neurology<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"step-2-limiting-the-results\">Step 2 \u2013 Limiting the Results<\/h4>\n\n\n\n<p>If you only want to see the single busiest department, you can limit the results to just the top row.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Department, COUNT(*) AS VisitCount\nFROM PatientVisits\nGROUP BY Department\nORDER BY VisitCount DESC\nLIMIT 1;\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Department<\/th><th>VisitCount<\/th><\/tr><\/thead><tbody><tr><td>Cardiology<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can use a free <strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-editor-tool\/\" target=\"_blank\" rel=\"noreferrer noopener\">online SQL compiler<\/a><\/strong> to practice as you go.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-combining-data-join\">5. Combining Data \u2013 JOIN<\/h3>\n\n\n\n<p>Often, the data you need is stored in multiple tables. To work with this related data, SQL provides the <code>JOIN<\/code> command, which merges tables based on a common column.<\/p>\n\n\n\n<p><code>JOIN<\/code> \u2013 merges rows from two or more tables based on a related column.<\/p>\n\n\n\n<p>Common types of <code>JOIN<\/code>s:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>INNER JOIN<\/code> \u2013 returns only rows with matching values in both tables.<\/li>\n\n\n\n<li><code>LEFT JOIN<\/code> \u2013 returns all rows from the left table &amp; matched rows from the right table (<code>NULL<\/code> if no match).<\/li>\n\n\n\n<li><code>RIGHT JOIN<\/code> \u2013 returns all rows from the right table &amp; matched rows from the left table (<code>NULL<\/code> if no match).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"primary-key-and-foreign-key\">Primary Key and Foreign Key:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Primary Key (PK)<\/strong> \u2013 a unique identifier for each row in a table. Ensures every record is distinct.<\/li>\n\n\n\n<li><strong>Foreign Key (FK)<\/strong> \u2013 a column in one table that references the Primary Key in another table. It establishes a relationship between tables.<\/li>\n<\/ul>\n\n\n\n<p>Using Primary Key and Foreign Key ensures data integrity and enables accurate <code>JOIN<\/code> operations.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"step-1-sample-datasets\">Step 1: Sample Datasets<\/h4>\n\n\n\n<p><strong>Table 1: Customers<\/strong> (Primary Key: CustomerID)<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerID<\/th><th>CustomerName<\/th><th>Country<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Alice Brown<\/td><td>USA<\/td><\/tr><tr><td>2<\/td><td>John Miller<\/td><td>Canada<\/td><\/tr><tr><td>3<\/td><td>Priya Sharma<\/td><td>India<\/td><\/tr><tr><td>4T<\/td><td>Robert Chen<\/td><td>China<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Table 2: Orders<\/strong> (Foreign Key: CustomerID referencing Customers.CustomerID)<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>OrderID<\/th><th>CustomerID<\/th><th>OrderAmount<\/th><th>OrderDate<\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>1<\/td><td>500<\/td><td>2024-03-01<\/td><\/tr><tr><td>102<\/td><td>2<\/td><td>1200<\/td><td>2024-03-02<\/td><\/tr><tr><td>103<\/td><td>1<\/td><td>700<\/td><td>2024-03-03<\/td><\/tr><tr><td>104<\/td><td>3<\/td><td>300<\/td><td>2024-03-04<\/td><\/tr><tr><td>105<\/td><td>5<\/td><td>200<\/td><td>2024-03-05<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-1-inner-join-customers-who-placed-orders\">Query 1 \u2013 INNER JOIN: Customers Who Placed Orders<\/h4>\n\n\n\n<p>An <code>INNER JOIN<\/code> allows us to see only the customers who have matching orders, along with their order information.<br>This query links customers to their specific orders and only returns those who have made a purchase.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Customers.CustomerName, Orders.OrderID, Orders.OrderAmount\nFROM Customers\nINNER JOIN Orders\nON Customers.CustomerID = Orders.CustomerID;\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>OrderID<\/th><th>OrderAmount<\/th><\/tr><\/thead><tbody><tr><td>Alice Brown<\/td><td>101<\/td><td>500<\/td><\/tr><tr><td>Alice Brown<\/td><td>103<\/td><td>700<\/td><\/tr><tr><td>John Miller<\/td><td>102<\/td><td>1200<\/td><\/tr><tr><td>Priya Sharma<\/td><td>104<\/td><td>300<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-2-left-join-all-customers-and-their-orders\">Query 2 \u2013 LEFT JOIN: All Customers and Their Orders<\/h4>\n\n\n\n<p>We use a <code>LEFT JOIN<\/code> when we need to display all customers, even if they haven't placed any orders. This method ensures no customer from the \"left\" table (Customers) is excluded from the report, regardless of their order activity.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Customers.CustomerName, Orders.OrderID, Orders.OrderAmount\nFROM Customers\nLEFT JOIN Orders\nON Customers.CustomerID = Orders.CustomerID;\n<\/pre><\/div>\n\n\n<p>If a customer has no orders, <code>OrderID<\/code> &amp; <code>OrderAmount<\/code> are <code>NULL<\/code>.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>OrderID<\/th><th>OrderAmount<\/th><\/tr><\/thead><tbody><tr><td>Alice Brown<\/td><td>101<\/td><td>500<\/td><\/tr><tr><td>Alice Brown<\/td><td>103<\/td><td>700<\/td><\/tr><tr><td>John Miller<\/td><td>102<\/td><td>1200<\/td><\/tr><tr><td>Priya Sharma<\/td><td>104<\/td><td>300<\/td><\/tr><tr><td>Robert Chen<\/td><td>NULL<\/td><td>NULL<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"query-3-right-join-all-orders-and-their-customers\">Query 3 \u2013 RIGHT JOIN: All Orders and Their Customers<\/h4>\n\n\n\n<p>A <code>RIGHT JOIN<\/code> is used to list all orders, even if they don't have matching customer information. This is useful for identifying data integrity issues, such as \"orphan\" orders that are in the system without a corresponding customer.<\/p>\n\n\n\n<p><strong>SQL Query:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT Customers.CustomerName, Orders.OrderID, Orders.OrderAmount\nFROM Customers\nRIGHT JOIN Orders\nON Customers.CustomerID = Orders.CustomerID;\n<\/pre><\/div>\n\n\n<p>If an order has a matching customer, <code>CustomerName<\/code> is included, and orders with no matching customer will show <code>NULL<\/code> for <code>CustomerName<\/code>.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>CustomerName<\/th><th>OrderID<\/th><th>OrderAmount<\/th><\/tr><\/thead><tbody><tr><td>Alice Brown<\/td><td>101<\/td><td>500<\/td><\/tr><tr><td>John Miller<\/td><td>102<\/td><td>1200<\/td><\/tr><tr><td>Alice Brown<\/td><td>103<\/td><td>700<\/td><\/tr><tr><td>Priya Sharma<\/td><td>104<\/td><td>300<\/td><\/tr><tr><td>NULL<\/td><td>105<\/td><td>200<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Learning SQL equips you with a universal skill for understanding and analyzing data, whether your goal is to generate reports, discover patterns, or answer complex business questions.<\/p>\n\n\n\n<p>SQL allows you to interact with large datasets in a structured and efficient manner. Its flexibility and scalability make it a core competency for data analysts, business intelligence professionals, and anyone who wants to convert raw data into actionable insights.<\/p>\n\n\n\n<p>If you wish to improve these skills and utilize them in real projects, then signing up for a <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-data-analytics-in-sql\">SQL Data Analytics course<\/a> will be the best option for you. You will learn practical methods and set up a solid base for a data-driven future career.<\/p>\n\n\n\n<p><strong>Suggested Read: <\/strong><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/\">List of 27 SQL Query Examples to Master Data Analysis<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.<\/p>\n","protected":false},"author":41,"featured_media":112893,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[36844],"content_type":[],"class_list":["post-112883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science","tag-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL for Data Analysis Tutorial<\/title>\n<meta name=\"description\" content=\"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL for Data Analysis Tutorial\" \/>\n<meta property=\"og:description\" content=\"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-31T06:00:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"SQL for Data Analysis Tutorial\",\"datePublished\":\"2025-10-31T06:00:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/\"},\"wordCount\":1967,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sql-data-analysis.webp\",\"keywords\":[\"sql\"],\"articleSection\":[\"Data Science and Analytics\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/\",\"name\":\"SQL for Data Analysis Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sql-data-analysis.webp\",\"datePublished\":\"2025-10-31T06:00:37+00:00\",\"description\":\"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sql-data-analysis.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/sql-data-analysis.webp\",\"width\":1408,\"height\":768,\"caption\":\"SQL for Data Analysis\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-for-data-analysis\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Science and Analytics\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL for Data Analysis Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL for Data Analysis Tutorial","description":"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/","og_locale":"en_US","og_type":"article","og_title":"SQL for Data Analysis Tutorial","og_description":"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2025-10-31T06:00:37+00:00","og_image":[{"width":1408,"height":768,"url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp","type":"image\/webp"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"SQL for Data Analysis Tutorial","datePublished":"2025-10-31T06:00:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/"},"wordCount":1967,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp","keywords":["sql"],"articleSection":["Data Science and Analytics"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/","name":"SQL for Data Analysis Tutorial","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp","datePublished":"2025-10-31T06:00:37+00:00","description":"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp","width":1408,"height":768,"caption":"SQL for Data Analysis"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-for-data-analysis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Data Science and Analytics","item":"https:\/\/www.mygreatlearning.com\/blog\/data-science\/"},{"@type":"ListItem","position":3,"name":"SQL for Data Analysis Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/10\/sql-data-analysis-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"This SQL tutorial covers essential techniques for filtering, summarizing, and joining data for effective analysis.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/112883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=112883"}],"version-history":[{"count":10,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/112883\/revisions"}],"predecessor-version":[{"id":112888,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/112883\/revisions\/112888"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/112893"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=112883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=112883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=112883"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=112883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}