Data Science Wallah
Data Science Wallah
  • 251
  • 1 344 310
Day 40 : Leetcode Sql Solution | 585. Investments in 2016 | Data Science Wallah
SQL Query to Calculate Total Investments in 2016 Based on Conditions - LeetCode 585 Solution
Introduction:
In this problem, we aim to calculate the total investment value in 2016 for policyholders who meet two conditions: they have the same total investment value in 2015 as other policyholders, and they live in a unique location (latitude and longitude pair). The result should be rounded to two decimal places.
Problem Description:
We are given a table called Insurance, which contains policyholder details including their policy ID, total investment values for 2015 and 2016, and their city's latitude and longitude. The task is to compute the sum of all total investment values for 2016 (tiv_2016) for policyholders who:
Have the same tiv_2015 value as one or more other policyholders.
Are not located in the same city as any other policyholder (i.e., their latitude and longitude pair is unique).
The result should be rounded to two decimal places.
Table Structure:
Table: Insurance
pid (int): Policy ID (Primary Key)
tiv_2015 (float): Total investment value in 2015.
tiv_2016 (float): Total investment value in 2016.
lat (float): Latitude of the policyholder's city.
lon (float): Longitude of the policyholder's city.
+-------------+-------+
| Column Name | Type |
+-------------+-------+
| pid | int |
| tiv_2015 | float |
| tiv_2016 | float |
| lat | float |
| lon | float |
+-------------+-------+
Step-by-Step Solution:
Identify policyholders with the same tiv_2015:
Group the data by tiv_2015 and filter for those that appear more than once.
Find unique city locations:
Group by the latitude (lat) and longitude (lon) to identify policyholders located in unique cities.
Filter based on both conditions:
Combine the two conditions to find the relevant policyholders.
Sum the total investment values for 2016:
Sum the tiv_2016 values of the filtered policyholders and round the result to two decimal places.
Writing the SQL Query:
SELECT ROUND(SUM(tiv_2016), 2) AS tiv_2016
FROM Insurance
WHERE tiv_2015 IN (
SELECT tiv_2015
FROM Insurance
GROUP BY tiv_2015
HAVING COUNT(*) greater than 1
)
AND (lat, lon) IN (
SELECT lat, lon
FROM Insurance
GROUP BY lat, lon
HAVING COUNT(*) = 1
);
Explanation of SQL Query:
The subquery for tiv_2015 groups records by tiv_2015 and ensures only values appearing more than once are included.
The subquery for lat and lon groups records by these columns to find unique locations.
The main query filters records based on both conditions and sums their tiv_2016 values, rounding the result to two decimal places.
What You Will Learn:
How to use GROUP BY and HAVING to filter records based on conditions.
Using subqueries to meet multiple criteria in SQL.
How to perform aggregation (SUM) and rounding (ROUND) in SQL queries.
#SQL #LeetCode #DataScience #InsuranceData #SQLQueries #GroupBy #DataAnalysis #PostgreSQL #TechTutorial #LearnSQL #DataEngineering
มุมมอง: 1

วีดีโอ

#2.1 | Google Colab for Python Programming | Google Colab Tutorial For Beginners
มุมมอง 219 ชั่วโมงที่ผ่านมา
Key Teaching Points for the TH-cam Video: Introduction to Google Colab: What Google Colab is and how it differs from traditional Python IDEs like PyCharm, VSCode, and Jupyter Notebooks. Cloud-based platform that allows you to write and execute Python code with no setup required. Google Colab Features: External Libraries Installation: How to install and use external libraries using !pip and !apt...
Day 39: SQL Query to Find the Person with the Most Friends  |  LeetCode 602 | Data Science Wallah
มุมมอง 52 ชั่วโมงที่ผ่านมา
Introduction: In this problem, we aim to find the person with the most friends by analyzing friend requests between users. Each request consists of a requester and an accepter, and we need to determine the individual with the highest number of accepted friends. Problem Description: We are given a table called RequestAccepted, which contains information about friend requests between users. The t...
#2 Python Tutorial for Beginners | Python Installation | PyCharm | Google Colab
มุมมอง 92 ชั่วโมงที่ผ่านมา
Description: In this video, we'll walk you through the complete process of installing Python and setting up PyCharm, one of the best IDEs for Python development. Learn how to check if Python is installed on your system, download the latest version, and configure the interpreter. We’ll also guide you through PyCharm installation and explain how to set up your first Python project. Whether you're...
Day 38: Most Toughest SQL problem |Leetcode 1341. Movie Rating | Data Science Wallah
มุมมอง 24 ชั่วโมงที่ผ่านมา
1341. Movie Rating - Leetcode SQL Query Solution Data Science Wallah Introduction: In this problem, we are tasked with writing SQL queries to find two key pieces of information from three different tables: The user who has rated the greatest number of movies (lexicographically smaller in case of a tie). The movie with the highest average rating in February 2020 (lexicographically smaller in cas...
Day 37: How to Use Lead () and Lag () in SQL | Leetcode 626. Exchange Seats | Data Science Wallah
มุมมอง 47 ชั่วโมงที่ผ่านมา
Swap Consecutive Students’ Seats - SQL Leetcode 626. Exchange Seats Data Science Wallah Introduction: In this SQL problem, we are tasked with swapping the seat id of every two consecutive students in a given table. If the number of students is odd, the last student's seat remains unchanged. We need to return the modified seating arrangement ordered by id. Problem Description: We are provided wi...
Day 36 :1978. Employees Whose Manager Left the Company- SQL Query Explanation
มุมมอง 39 ชั่วโมงที่ผ่านมา
1978. Employees Whose Manager Left the Company Leetcode- SQL Query Explanation Introduction: In this SQL problem, we are asked to find the employees whose salary is less than $30,000 and whose manager has left the company. We’ll break down how to approach this using SQL to get the required results efficiently. Problem Description: We have an Employees table that contains details about employees...
#1 Python Tutorial for Beginners | Introduction to Python
มุมมอง 149 ชั่วโมงที่ผ่านมา
1. Introduction to Python Python is a versatile, general-purpose programming language that is rapidly growing in popularity. It is used across multiple domains like machine learning, software development, web development, and more. Python is popular for being easy to learn, write, and implement. 2. Python's Popularity Growth Factors: Python's growth is driven by an increase in the number of dev...
Day 35: 1907. Count Salary Categories| SQL LeetCode Solution | Data Science Wallah
มุมมอง 312 ชั่วโมงที่ผ่านมา
Classify data using CASE,LEFT JOIN and UNION ALL. Data Science Wallah Introduction: In this SQL problem, you are asked to categorize salaries into three distinct groups based on income ranges. The goal is to count how many bank accounts fall under each salary category, ensuring that all three categories are represented, even if some have no accounts. Problem Description: You are provided with a...
Day 34 : Last Person to Fit in the Bus | SQL LeetCode Solution in Hindi | | Data Science Wallah
มุมมอง 414 ชั่วโมงที่ผ่านมา
1204. Last Person to Fit in the Bus | SQL LeetCode Solution Data Science Wallah Introduction: In this SQL problem, you are tasked with finding the last person who can board a bus without exceeding its weight limit. Each person has a specified turn in which they will board, and the bus can only take people one at a time until the total weight reaches or exceeds 1000 kilograms. Problem Descriptio...
Day 33: Product Price at a Given Date | SQL LeetCode Solution in Hindi | Data Science Wallah
มุมมอง 416 ชั่วโมงที่ผ่านมา
1164. Product Price at a Given Date Data Science Wallah Introduction: In this SQL problem, you are tasked with determining the price of all products on a specific date (2019-08-16). The price of each product can change over time, and any product that has no price changes will default to a price of 10. Problem Description: You are given a table Products that contains the product_id, the new_pric...
Day 32: Consecutive Numbers | SQL LeetCode Solution in Hindi | Data Science Wallah
มุมมอง 419 ชั่วโมงที่ผ่านมา
180. Consecutive Numbers | SQL LeetCode Solution Introduction: In this SQL problem, you are tasked with identifying numbers that appear at least three times consecutively in a table. This problem tests your ability to handle sequential data using SQL. Problem Description: You are provided with a table called Logs that contains two columns: id and num. Your task is to find all numbers that appea...
Day 31 : Triangle Judgement | SQL LeetCode Solution 610 | Data Science Wallah
มุมมอง 321 ชั่วโมงที่ผ่านมา
610. Triangle Judgement | SQL LeetCode Solution Introduction: In this SQL challenge, you'll be determining whether three line segments can form a triangle. This problem tests your ability to implement basic geometric rules in SQL. Specifically, the triangle inequality theorem must be applied to check whether a triangle can be formed with given side lengths. Problem Description: You are provided...
Day 30 : Primary Department for Each Employee | SQL LeetCode 1789 Solution | Data Science Wallah
มุมมอง 4วันที่ผ่านมา
Day 30 : Primary Department for Each Employee | SQL LeetCode 1789 Solution | Data Science Wallah
Day 29 : Classes More Than 5 Students | SQL LeetCode 596 Solution in Hindi | Data Science Wallah
มุมมอง 7วันที่ผ่านมา
Day 29 : Classes More Than 5 Students | SQL LeetCode 596 Solution in Hindi | Data Science Wallah
Day 28 :SQL LeetCode | 1070. Product Sales Analysis III | Data Science Wallah
มุมมอง 50วันที่ผ่านมา
Day 28 :SQL LeetCode | 1070. Product Sales Analysis III | Data Science Wallah
Day 27 :Customers Who Bought All Products | SQL LeetCode 1045 Solution in Hindi
มุมมอง 10วันที่ผ่านมา
Day 27 :Customers Who Bought All Products | SQL LeetCode 1045 Solution in Hindi
Day 26 : Find the Largest Single Number | SQL LeetCode Solution 619 in Hindi
มุมมอง 6314 วันที่ผ่านมา
Day 26 : Find the Largest Single Number | SQL LeetCode Solution 619 in Hindi
What is Activation function in Neural Network? Types of Activation Function in Neural Network | DSW
มุมมอง 2314 วันที่ผ่านมา
What is Activation function in Neural Network? Types of Activation Function in Neural Network | DSW
Understanding Multi-Layer Perceptron (MLP) | Complete Hindi tutorial | Live Coding | Deep learning
มุมมอง 2514 วันที่ผ่านมา
Understanding Multi-Layer Perceptron (MLP) | Complete Hindi tutorial | Live Coding | Deep learning
Day 25 : Find Followers Count in a Social Media App | SQL LeetCode Solution 1729
มุมมอง 1314 วันที่ผ่านมา
Day 25 : Find Followers Count in a Social Media App | SQL LeetCode Solution 1729
Handwritten Digit Classification using TensorFlow 2.x | Single Layer Perceptron in Hindi | Live Demo
มุมมอง 1614 วันที่ผ่านมา
Handwritten Digit Classification using TensorFlow 2.x | Single Layer Perceptron in Hindi | Live Demo
Multi-Layer Perceptron |Feed Forward Learning |Back Propagation | Hidden Layers | Hindi Tutorial
มุมมอง 2314 วันที่ผ่านมา
Multi-Layer Perceptron |Feed Forward Learning |Back Propagation | Hidden Layers | Hindi Tutorial
Deep Learning Explained | Complete Beginner's Guide in Hindi | Deep Learning Tutorial in Hindi
มุมมอง 4114 วันที่ผ่านมา
Deep Learning Explained | Complete Beginner's Guide in Hindi | Deep Learning Tutorial in Hindi
Day 24: SQl Filtering by Date Range | GROUP BY Clause in SQL | LeetCode 1141 explained in Hindi
มุมมอง 3814 วันที่ผ่านมา
Day 24: SQl Filtering by Date Range | GROUP BY Clause in SQL | LeetCode 1141 explained in Hindi
Day 23 : How to Use COUNT(DISTINCT) and GROUP BY Effectively | Leetcode 2356 explained in Hindi
มุมมอง 2514 วันที่ผ่านมา
Day 23 : How to Use COUNT(DISTINCT) and GROUP BY Effectively | Leetcode 2356 explained in Hindi
Day 22 : SQL beginners understand self-joins, date arithmetic, and how to structure complex queries.
มุมมอง 2714 วันที่ผ่านมา
Day 22 : SQL beginners understand self-joins, date arithmetic, and how to structure complex queries.
Day 21 : How to use Common Table Expressions (CTEs) to break down complex queries
มุมมอง 4014 วันที่ผ่านมา
Day 21 : How to use Common Table Expressions (CTEs) to break down complex queries
Day 20 : SQL for Beginners: Grouping, Aggregation, and Date Formatting | Monthly Transactions I
มุมมอง 12514 วันที่ผ่านมา
Day 20 : SQL for Beginners: Grouping, Aggregation, and Date Formatting | Monthly Transactions I
Day 19 - Mastering Aggregation Functions & Percentage Calculation | Queries Quality and Percentage
มุมมอง 3021 วันที่ผ่านมา
Day 19 - Mastering Aggregation Functions & Percentage Calculation | Queries Quality and Percentage

ความคิดเห็น

  • @vuppununthalashobharani6635
    @vuppununthalashobharani6635 13 ชั่วโมงที่ผ่านมา

    return 0; ✅ return 0?❌

  • @Relaxinghome188
    @Relaxinghome188 23 ชั่วโมงที่ผ่านมา

    Vicco Turmeric 🤣🤣

  • @PriyankaGupta-qk2mc
    @PriyankaGupta-qk2mc 4 วันที่ผ่านมา

    🙂

  • @thedevilsgrimreaper2979
    @thedevilsgrimreaper2979 7 วันที่ผ่านมา

    Saw someone so much creative after poorav jha.

  • @arifali009
    @arifali009 8 วันที่ผ่านมา

    Nhi hoga be kue pagal bana raha h

  • @ujwal.d
    @ujwal.d 10 วันที่ผ่านมา

    Yes

  • @DataScienceWallah
    @DataScienceWallah 10 วันที่ผ่านมา

    Hi all, if you want to learn about Data Science,Python,SQl,Machine Learning kindly join my channel . 100 % FREE with all course materials

  • @Devil_9806
    @Devil_9806 10 วันที่ผ่านมา

    Isse kahete hai degree pe aache tarah se mutna 😂

  • @muskuraiye79
    @muskuraiye79 10 วันที่ผ่านมา

    Best song ever heard

  • @gurugavali7264
    @gurugavali7264 11 วันที่ผ่านมา

    Terms and conditions applied

  • @SSCKamessi
    @SSCKamessi 12 วันที่ผ่านมา

    लेकिन इन सबका BSc से क्या लेना देना 😂

    • @DataScienceWallah
      @DataScienceWallah 12 วันที่ผ่านมา

      basic Maths and Stats Padi jaati hai BSC mai wo kaam aati hai

  • @Yash_Rajput_0
    @Yash_Rajput_0 12 วันที่ผ่านมา

    chai wala 🙂

  • @itiswhatitis023
    @itiswhatitis023 13 วันที่ผ่านมา

    Kabutar science 🕊️ supremacy 🤑😤

  • @tasmisa6778
    @tasmisa6778 13 วันที่ผ่านมา

    Hope it'll help

    • @DataScienceWallah
      @DataScienceWallah 12 วันที่ผ่านมา

      Yes it's tried and tested method so will definitely work

  • @Bets009
    @Bets009 13 วันที่ผ่านมา

    Bhai ek Mechanical Engineer pe bana do 😂😂

  • @vaishnavi20050
    @vaishnavi20050 13 วันที่ผ่านมา

    😂😂

  • @tejaskumar4887
    @tejaskumar4887 14 วันที่ผ่านมา

    Bhai ke paas 1 lakh se bhi upar ka laptop hai ha which jisme purple light jal rahi thi name acer predator helios 16

  • @Rabaika_here
    @Rabaika_here 14 วันที่ผ่านมา

    😂😂😂😂

  • @Someone-uq4qg
    @Someone-uq4qg 14 วันที่ผ่านมา

    Bahi meri clg ki fees bhi utni hi he😂😂

  • @ParamDham_369
    @ParamDham_369 14 วันที่ผ่านมา

    Inke bāp kā dream...😅

  • @vivekkulkarni256
    @vivekkulkarni256 14 วันที่ผ่านมา

    Nhi khud ki pasand se liya hhu

  • @piyalighosh4939
    @piyalighosh4939 14 วันที่ผ่านมา

    “hot puneet superstar image” 😅😅

  • @FREAKY-i9z
    @FREAKY-i9z 14 วันที่ผ่านมา

    Legend noticed "hot punnet superstar images " in the right of 4line codes😂😂😂

  • @kaonashi93
    @kaonashi93 14 วันที่ผ่านมา

    😂😂😂😂😂😂😂😂😂

  • @dilawarrana5999
    @dilawarrana5999 14 วันที่ผ่านมา

    Nirma Engineering College Bihar ❤

  • @earnmoneyathome6252
    @earnmoneyathome6252 14 วันที่ผ่านมา

    Computer science is the worst branch. Don't fall in these traps it will ruin your life like mine

  • @skchad69
    @skchad69 14 วันที่ผ่านมา

    😂😂

  • @Nazkajahan-m2o
    @Nazkajahan-m2o 14 วันที่ผ่านมา

    Vico termaric ayurvedic cream 😂😂

  • @RUDRAGAMER46
    @RUDRAGAMER46 14 วันที่ผ่านมา

    "Engineering inke baap ka dream" was epic

  • @Avinashxff
    @Avinashxff 14 วันที่ผ่านมา

    Coding is very easy....😂for me

    • @DataScienceWallah
      @DataScienceWallah 12 วันที่ผ่านมา

      Share to all who want to learn coding, thanks 😊

  • @AmaankhanPathan-c1g
    @AmaankhanPathan-c1g 14 วันที่ผ่านมา

    Bro can beat mc stan

  • @AnkitaKishore-b5n
    @AnkitaKishore-b5n 14 วันที่ผ่านมา

    Gazab😂😂

  • @VishalFTW
    @VishalFTW 14 วันที่ผ่านมา

    8.5 lakh is too much

  • @muhammadfurqanalam
    @muhammadfurqanalam 14 วันที่ผ่านมา

    Engineering kb se baap k dream ho gaya ? Neet bolte toa mante v

  • @artbyshlokkumarchoudhary6608
    @artbyshlokkumarchoudhary6608 14 วันที่ผ่านมา

    Opition C is correct which is my_dict.has_key("key")✔

  • @RanjitSarma-uv9in
    @RanjitSarma-uv9in 14 วันที่ผ่านมา

    His lagewriting is better than my handwriting ❤😊

  • @thakur7565
    @thakur7565 14 วันที่ผ่านมา

    me too commerce wala hu mujhe kya 😂

  • @jagneswarpanda4188
    @jagneswarpanda4188 14 วันที่ผ่านมา

    Hot puneet superstar image??

  • @MadhabNayek
    @MadhabNayek 14 วันที่ผ่านมา

    "HOT PUNEET SUPERSTAR IMAGE" 😂😂

  • @_motivation_24
    @_motivation_24 14 วันที่ผ่านมา

    IIT BOMBAY BE LIKE -ab sirf 4 lakh me😂😂

  • @AnishkumarHosalli
    @AnishkumarHosalli 14 วันที่ผ่านมา

    Aaa😂😂😂😂😂😂😂😂😂😂😂😂

  • @lifo_patra
    @lifo_patra 14 วันที่ผ่านมา

    6,00,000❎ 8,50,000✅😂😂😂

  • @HarshitShukla-d7w
    @HarshitShukla-d7w 14 วันที่ผ่านมา

    Who else notices "Hot puneetstar images"😂😂😂

  • @krishinavenit7876
    @krishinavenit7876 14 วันที่ผ่านมา

    Wt about aerospace students😭😭😭🤧rocket banagee 🤧

  • @NaveenSharma-b7z
    @NaveenSharma-b7z 14 วันที่ผ่านมา

    Mera future 😂😂😂😂

  • @Mikey82127
    @Mikey82127 14 วันที่ผ่านมา

    Jai shree ram ❤❤

  • @VISHALKUMAR-qy3mb
    @VISHALKUMAR-qy3mb 14 วันที่ผ่านมา

    Vo bhi salo ne online c++ compilers khol rakha hai😂. Abe enviornment bhi set-up nhi krne aata kya 😂

  • @Neeraj--bhai0001
    @Neeraj--bhai0001 14 วันที่ผ่านมา

    6 lakh se 8.50 lakh kya discount hai😂😂

  • @Neeraj--bhai0001
    @Neeraj--bhai0001 14 วันที่ผ่านมา

    😂😂