Skip to content

Commit 667a248

Browse files
committed
Upload 186
1 parent 62caf0b commit 667a248

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-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-185-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-186-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -219,6 +219,7 @@ Because this project necessitated a framework to enable consistent daily practic
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` |
221221
| 185 | [Sales Analysis I](https://leetcode.com/problems/sales-analysis-i/description/) | [Solution](solutions/185_sales_analysis_i.md) | LeetCode | Easy | |
222+
| 186 | [Sales Analysis II](https://leetcode.com/problems/sales-analysis-ii/description/) | [Solution](solutions/186_sales_analysis_ii.md) | LeetCode | Easy | `STRING_AGG` vs `GROUP_CONCAT` |
222223
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
223224
<!--- cSpell:enable --->
224225

solutions/186_sales_analysis_ii.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SQL Everyday \#186
2+
3+
## Sales Analysis II
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
Write a solution to report the **buyers** who have bought *S8* but not *iPhone*. Note that *S8* and *iPhone* are products presented in the `Product` table.
11+
12+
Return the resulting table in **any order**. [[Full Description](https://leetcode.com/problems/sales-analysis-ii/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
WITH cte AS (
19+
SELECT
20+
s.buyer_id
21+
,STRING_AGG(p.product_name, ',') AS products
22+
FROM Sales AS s
23+
JOIN Product AS p ON s.product_id = p.product_id
24+
GROUP BY s.buyer_id
25+
)
26+
SELECT
27+
buyer_id
28+
FROM cte
29+
WHERE products LIKE '%S8%'
30+
AND products NOT LIKE '%iPhone%'
31+
;
32+
```
33+
34+
## Site Solution
35+
36+
```sql
37+
-- LeetCode Solution
38+
SELECT DISTINCT s.buyer_id
39+
FROM Sales s
40+
JOIN Product p
41+
ON s.product_id = p.product_id
42+
GROUP BY s.buyer_id
43+
HAVING GROUP_CONCAT(p.product_name) LIKE '%S8%'
44+
AND GROUP_CONCAT(p.product_name) NOT LIKE '%iPhone%'
45+
```
46+
47+
## Notes
48+
49+
TBD
50+
51+
## NB
52+
53+
`STRING_AGG` vs `GROUP_CONCAT`
54+
55+
Go to [Index](../?tab=readme-ov-file#index)\
56+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)