Skip to content

Commit 80eca63

Browse files
authored
Create 1421 - npv-queries.md
1 parent a1633b8 commit 80eca63

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: npv-queries
3+
title: 1421. NPV Queries
4+
sidebar_label: 1421 - npv-queries
5+
description: "This is a solution to LeetCode problems 1421."
6+
---
7+
8+
SQL Schema
9+
Table: NPV
10+
11+
+---------------+---------+
12+
| Column Name | Type |
13+
+---------------+---------+
14+
| id | int |
15+
| year | int |
16+
| npv | int |
17+
+---------------+---------+
18+
(id, year) is the primary key of this table.
19+
The table contains information about the id and the year of each inventory and the corresponding net present value.
20+
21+
22+
Table: Queries
23+
24+
+---------------+---------+
25+
| Column Name | Type |
26+
+---------------+---------+
27+
| id | int |
28+
| year | int |
29+
+---------------+---------+
30+
(id, year) is the primary key of this table.
31+
The table contains information about the id and the year of each inventory query.
32+
33+
34+
Write an SQL query to find the npv of each query in the queries table.
35+
36+
Return the result table in any order.
37+
38+
The query result format is as follows:
39+
40+
NPV table:
41+
+------+--------+--------+
42+
| id | year | npv |
43+
+------+--------+--------+
44+
| 1 | 2018 | 100 |
45+
| 7 | 2020 | 30 |
46+
| 13 | 2019 | 40 |
47+
| 1 | 2019 | 113 |
48+
| 2 | 2008 | 121 |
49+
| 3 | 2009 | 12 |
50+
| 11 | 2020 | 99 |
51+
| 7 | 2019 | 0 |
52+
+------+--------+--------+
53+
54+
Queries table:
55+
+------+--------+
56+
| id | year |
57+
+------+--------+
58+
| 1 | 2019 |
59+
| 2 | 2008 |
60+
| 3 | 2009 |
61+
| 7 | 2018 |
62+
| 7 | 2019 |
63+
| 7 | 2020 |
64+
| 13 | 2019 |
65+
+------+--------+
66+
67+
Result table:
68+
+------+--------+--------+
69+
| id | year | npv |
70+
+------+--------+--------+
71+
| 1 | 2019 | 113 |
72+
| 2 | 2008 | 121 |
73+
| 3 | 2009 | 12 |
74+
| 7 | 2018 | 0 |
75+
| 7 | 2019 | 0 |
76+
| 7 | 2020 | 30 |
77+
| 13 | 2019 | 40 |
78+
+------+--------+--------+
79+
80+
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.

0 commit comments

Comments
 (0)