Skip to content

Commit ee325e4

Browse files
add 1069
1 parent 0100870 commit ee325e4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ Your ideas/fixes/algorithms are more than welcome!
799799

800800
| # | Title | Solutions | Time | Space | Difficulty | Tag
801801
|-----|----------------|---------------|---------------|---------------|-------------|--------------
802+
|1069|[Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii/)|[Solution](../master/database/_1069.sql) | | | Easy |
802803
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/)|[Solution](../master/database/_627.sql) | | | Easy |
803804
|626|[Exchange Seats](https://leetcode.com/problems/exchange-seats/)|[Solution](../master/database/_626.sql) | | | Medium |
804805
|620|[Not Boring Movies](https://leetcode.com/problems/not-boring-movies/)|[Solution](../master/database/_620.sql) | | | Easy |

database/_1069.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
-- 1069. Product Sales Analysis II
2+
--Table: Sales
3+
--
4+
--+-------------+-------+
5+
--| Column Name | Type |
6+
--+-------------+-------+
7+
--| sale_id | int |
8+
--| product_id | int |
9+
--| year | int |
10+
--| quantity | int |
11+
--| price | int |
12+
--+-------------+-------+
13+
--sale_id is the primary key of this table.
14+
--product_id is a foreign key to Product table.
15+
--Note that the price is per unit.
16+
--Table: Product
17+
--
18+
--+--------------+---------+
19+
--| Column Name | Type |
20+
--+--------------+---------+
21+
--| product_id | int |
22+
--| product_name | varchar |
23+
--+--------------+---------+
24+
--product_id is the primary key of this table.
25+
--
26+
--
27+
--Write an SQL query that reports the total quantity sold for every product id.
28+
--
29+
--The query result format is in the following example:
30+
--
31+
--Sales table:
32+
--+---------+------------+------+----------+-------+
33+
--| sale_id | product_id | year | quantity | price |
34+
--+---------+------------+------+----------+-------+
35+
--| 1 | 100 | 2008 | 10 | 5000 |
36+
--| 2 | 100 | 2009 | 12 | 5000 |
37+
--| 7 | 200 | 2011 | 15 | 9000 |
38+
--+---------+------------+------+----------+-------+
39+
--
40+
--Product table:
41+
--+------------+--------------+
42+
--| product_id | product_name |
43+
--+------------+--------------+
44+
--| 100 | Nokia |
45+
--| 200 | Apple |
46+
--| 300 | Samsung |
47+
--+------------+--------------+
48+
--
49+
--Result table:
50+
--+--------------+----------------+
51+
--| product_id | total_quantity |
52+
--+--------------+----------------+
53+
--| 100 | 22 |
54+
--| 200 | 15 |
55+
--+--------------+----------------+
56+
57+
SELECT product_id, SUM(quantity) AS total_quantity FROM Sales GROUP BY product_id;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy