Skip to content

Commit 62caf0b

Browse files
committed
Upload 185
1 parent 4b114ef commit 62caf0b

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- markdownlint-disable MD041 -->
22
[![eevveerryyddaayy release](https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg)](https://github.com/ggeerraarrdd/eevveerryyddaayy/)
3-
[![Solved](https://img.shields.io/badge/solved-184-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-185-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -218,6 +218,7 @@ Because this project necessitated a framework to enable consistent daily practic
218218
| 182 | [Low-Quality Problems](https://leetcode.com/problems/low-quality-problems/description/) | [Solution](solutions/182_low_quality_problems.md) | LeetCode | Easy | |
219219
| 183 | [Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii/description/) | [Solution](solutions/183_product_sales_analysis_ii.md) | LeetCode | Easy | |
220220
| 184 | [Project Employees II](https://leetcode.com/problems/project-employees-ii/description/) | [Solution](solutions/184_project_employees_ii.md) | LeetCode | Easy | Window function w/ `GROUP BY` |
221+
| 185 | [Sales Analysis I](https://leetcode.com/problems/sales-analysis-i/description/) | [Solution](solutions/185_sales_analysis_i.md) | LeetCode | Easy | |
221222
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
222223
<!--- cSpell:enable --->
223224

solutions/185_sales_analysis_i.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SQL Everyday \#185
2+
3+
## Sales Analysis I
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution that reports the best **seller** by total sales price, If there is a tie, report them all.
11+
12+
Return the resulting table in **any order**. [[Full Description](https://leetcode.com/problems/sales-analysis-i/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
WITH cte AS (
19+
SELECT
20+
seller_id
21+
,RANK() OVER (ORDER BY SUM(price) DESC) AS rank_total
22+
FROM Sales
23+
GROUP BY seller_id
24+
)
25+
SELECT
26+
seller_id
27+
FROM cte
28+
WHERE rank_total = 1
29+
;
30+
```
31+
32+
## Site Solution
33+
34+
```sql
35+
-- LeetCode Solution
36+
WITH aggregated_sales AS (
37+
SELECT
38+
seller_id,
39+
SUM(price) AS total_price
40+
FROM
41+
Sales
42+
GROUP BY
43+
seller_id
44+
)
45+
SELECT
46+
seller_id
47+
FROM
48+
aggregated_sales
49+
WHERE
50+
total_price = (
51+
SELECT
52+
MAX(total_price)
53+
FROM
54+
aggregated_sales
55+
);
56+
57+
-- Code Author: Brian
58+
-- https://leetcode.com/problems/sales-analysis-i/solutions/311519/mysql-solution
59+
SELECT seller_id
60+
FROM Sales
61+
GROUP BY seller_id
62+
HAVING SUM(PRICE) >= all (
63+
SELECT SUM(PRICE)
64+
FROM Sales
65+
GROUP BY seller_id
66+
)
67+
```
68+
69+
## Notes
70+
71+
TBD
72+
73+
## NB
74+
75+
TBD
76+
77+
Go to [Index](../?tab=readme-ov-file#index)\
78+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)