From 80eca632a0518ce26c1b213da6801dd457f7a84e Mon Sep 17 00:00:00 2001 From: Vedang Maheshwari <98143931+vedang1@users.noreply.github.com> Date: Tue, 30 Jul 2024 02:04:09 +0530 Subject: [PATCH] Create 1421 - npv-queries.md --- .../1400-1499/1421 - npv-queries.md | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dsa-solutions/lc-solutions/1400-1499/1421 - npv-queries.md diff --git a/dsa-solutions/lc-solutions/1400-1499/1421 - npv-queries.md b/dsa-solutions/lc-solutions/1400-1499/1421 - npv-queries.md new file mode 100644 index 000000000..cf06164df --- /dev/null +++ b/dsa-solutions/lc-solutions/1400-1499/1421 - npv-queries.md @@ -0,0 +1,80 @@ +--- +id: npv-queries +title: 1421. NPV Queries +sidebar_label: 1421 - npv-queries +description: "This is a solution to LeetCode problems 1421." +--- + +SQL Schema +Table: NPV + ++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| year | int | +| npv | int | ++---------------+---------+ +(id, year) is the primary key of this table. +The table contains information about the id and the year of each inventory and the corresponding net present value. + + +Table: Queries + ++---------------+---------+ +| Column Name | Type | ++---------------+---------+ +| id | int | +| year | int | ++---------------+---------+ +(id, year) is the primary key of this table. +The table contains information about the id and the year of each inventory query. + + +Write an SQL query to find the npv of each query in the queries table. + +Return the result table in any order. + +The query result format is as follows: + +NPV table: ++------+--------+--------+ +| id | year | npv | ++------+--------+--------+ +| 1 | 2018 | 100 | +| 7 | 2020 | 30 | +| 13 | 2019 | 40 | +| 1 | 2019 | 113 | +| 2 | 2008 | 121 | +| 3 | 2009 | 12 | +| 11 | 2020 | 99 | +| 7 | 2019 | 0 | ++------+--------+--------+ + +Queries table: ++------+--------+ +| id | year | ++------+--------+ +| 1 | 2019 | +| 2 | 2008 | +| 3 | 2009 | +| 7 | 2018 | +| 7 | 2019 | +| 7 | 2020 | +| 13 | 2019 | ++------+--------+ + +Result table: ++------+--------+--------+ +| id | year | npv | ++------+--------+--------+ +| 1 | 2019 | 113 | +| 2 | 2008 | 121 | +| 3 | 2009 | 12 | +| 7 | 2018 | 0 | +| 7 | 2019 | 0 | +| 7 | 2020 | 30 | +| 13 | 2019 | 40 | ++------+--------+--------+ + +The npv value of (7, 2018) is not present in the NPV table, so we consider it as 0. The npv values of all other queries can be found in the NPV table.