Skip to content

Commit cf7e740

Browse files
refactor 1082
1 parent b0219a2 commit cf7e740

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

database/_1082.sql

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,3 @@
1-
--1082. Sales Analysis I
2-
--
3-
--Table: Product
4-
--
5-
--+--------------+---------+
6-
--| Column Name | Type |
7-
--+--------------+---------+
8-
--| product_id | int |
9-
--| product_name | varchar |
10-
--| unit_price | int |
11-
--+--------------+---------+
12-
--product_id is the primary key of this table.
13-
--Table: Sales
14-
--
15-
--+-------------+---------+
16-
--| Column Name | Type |
17-
--+-------------+---------+
18-
--| seller_id | int |
19-
--| product_id | int |
20-
--| buyer_id | int |
21-
--| sale_date | date |
22-
--| quantity | int |
23-
--| price | int |
24-
--+------ ------+---------+
25-
--This table has no primary key, it can have repeated rows.
26-
--product_id is a foreign key to Product table.
27-
--
28-
--
29-
--Write an SQL query that reports the best seller by total sales price, If there is a tie, report them all.
30-
--
31-
--The query result format is in the following example:
32-
--
33-
--Product table:
34-
--+------------+--------------+------------+
35-
--| product_id | product_name | unit_price |
36-
--+------------+--------------+------------+
37-
--| 1 | S8 | 1000 |
38-
--| 2 | G4 | 800 |
39-
--| 3 | iPhone | 1400 |
40-
--+------------+--------------+------------+
41-
--
42-
--Sales table:
43-
--+-----------+------------+----------+------------+----------+-------+
44-
--| seller_id | product_id | buyer_id | sale_date | quantity | price |
45-
--+-----------+------------+----------+------------+----------+-------+
46-
--| 1 | 1 | 1 | 2019-01-21 | 2 | 2000 |
47-
--| 1 | 2 | 2 | 2019-02-17 | 1 | 800 |
48-
--| 2 | 2 | 3 | 2019-06-02 | 1 | 800 |
49-
--| 3 | 3 | 4 | 2019-05-13 | 2 | 2800 |
50-
--+-----------+------------+----------+------------+----------+-------+
51-
--
52-
--Result table:
53-
--+-------------+
54-
--| seller_id |
55-
--+-------------+
56-
--| 1 |
57-
--| 3 |
58-
--+-------------+
59-
--Both sellers with id 1 and 3 sold products with the most total price of 2800.
60-
61-
--# Write your MySQL query statement below
62-
--credit: https://leetcode.com/problems/sales-analysis-i/discuss/349042/MySQL-Solution
63-
641
select seller_id from Sales as seller_id
652
group by seller_id
663
having sum(price) = (

0 commit comments

Comments
 (0)