Skip to content

Commit 02109ed

Browse files
committed
Align existing files with new content structure of template file
1 parent 6daf1b9 commit 02109ed

File tree

128 files changed

+640
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+640
-16
lines changed

solutions/001_histogram_of_tweets.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Easy
99

1010
Assume you're given a table Twitter tweet data, write a query to obtain a histogram of tweets posted per user in 2022. Output the tweet count per user as the bucket and the number of Twitter users who fall into that bucket. In other words, group the users by the number of tweets they posted in 2022 and count the number of users in each group. [[Full Description](https://datalemur.com/questions/sql-histogram-tweets)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
WITH cte AS (
@@ -28,9 +28,19 @@ GROUP BY count
2828
;
2929
```
3030

31+
## Site Solution
32+
33+
```sql
34+
-- TBD
35+
```
36+
3137
## Notes
3238

3339
TODO
3440

41+
## NB
42+
43+
TBD
44+
3545
Go to [Table of Contents](/README.md#contents)\
3646
Go to [Overview](/README.md)

solutions/002_users_third_transaction.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
Write a query to obtain the third transaction of every user. Output the user id, spend and transaction date. [[Full Description](https://datalemur.com/questions/sql-third-transaction)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
WITH cte AS (
@@ -29,9 +29,19 @@ WHERE transaction = 3
2929
;
3030
```
3131

32+
## Site Solution
33+
34+
```sql
35+
-- TBD
36+
```
37+
3238
## Notes
3339

3440
TODO
3541

42+
## NB
43+
44+
TBD
45+
3646
Go to [Table of Contents](/README.md#contents)\
3747
Go to [Overview](/README.md)

solutions/003_second_highest_salary.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
Your manager is keen on understanding the pay distribution and asks you to determine the second highest salary among all employees. It's possible that multiple employees may share the same second highest salary. In case of duplicate, display the salary only once. [[Full Description](https://datalemur.com/questions/sql-second-highest-salary)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -26,7 +26,11 @@ FROM cte
2626
WHERE rank = 2
2727
LIMIT 1
2828
;
29+
```
30+
31+
## Site Solution
2932

33+
```sql
3034
-- DataLemur Solution
3135
SELECT MAX(salary) AS second_highest_salary
3236
FROM employee
@@ -40,5 +44,9 @@ WHERE salary < (
4044

4145
TODO
4246

47+
## NB
48+
49+
TBD
50+
4351
Go to [Table of Contents](/README.md#contents)\
4452
Go to [Overview](/README.md)

solutions/004_sending_vs_opening_snaps.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
Write a query to obtain a breakdown of the time spent sending vs. opening snaps as a percentage of total time spent on these activities grouped by age group. Round the percentage to 2 decimal places in the output. [[Full Description](https://datalemur.com/questions/time-spent-snaps)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -61,7 +61,11 @@ SELECT
6161
FROM cte4
6262
JOIN cte5 ON cte4.age_bucket = cte5.age_bucket
6363
;
64+
```
65+
66+
## Site Solution
6467

68+
```sql
6569
-- DataLemur Solution
6670
SELECT
6771
age.age_bucket,
@@ -82,5 +86,9 @@ GROUP BY age.age_bucket;
8286

8387
* One of the reasons I started this personal SQL Everyday chellenge is to learn SQL concepts and techniques new to me. This problem delivered with [`FILTER()`](https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-AGGREGATES) from DataLemur's solutions. The reduction of lines from my query to that solution is remarkable.
8488

89+
## NB
90+
91+
TBD
92+
8593
Go to [Table of Contents](/README.md#contents)\
8694
Go to [Overview](/README.md)

solutions/005_highest-grossing_items.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
Write a query to obtain a breakdown of the time spent sending vs. opening snaps as a percentage of total time spent on these activities grouped by age group. Round the percentage to 2 decimal places in the output. [[Full Description](https://datalemur.com/questions/time-spent-snaps)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -39,7 +39,11 @@ FROM cte2
3939
WHERE cat_rank < 3
4040
ORDER BY category, cat_rank
4141
;
42+
```
43+
44+
## Site Solution
4245

46+
```sql
4347
-- DataLemur Solution
4448
WITH ranked_spending_cte AS (
4549
SELECT
@@ -66,5 +70,9 @@ ORDER BY category, ranking;
6670
* The key is knowing the difference between [`RANK()` and `DENSE_RANK`](https://www.google.com/search?q=rank()+vs+dense_rank()).
6771
* New to me: You can use an aggregate function in the `OVER()` clause of window function. This would have eliminated one CTE in my submitted solution.
6872

73+
## NB
74+
75+
TBD
76+
6977
Go to [Table of Contents](/README.md#contents)\
7078
Go to [Overview](/README.md)

solutions/006_top_three_salaries.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ As part of an ongoing analysis of salary distribution within the company, your m
1111

1212
You're tasked with identifying these high earners across all departments. Write a query to display the employee's name along with their department name and salary. In case of duplicates, sort the results of department name in ascending order, then by salary in descending order. If multiple employees have the same salary, then order them alphabetically. [[Full Description](https://datalemur.com/questions/sql-top-three-salaries)]
1313

14-
## Solution
14+
## Submitted Solution
1515

1616
```sql
1717
-- Submitted Solution
@@ -34,9 +34,19 @@ ORDER BY department_name ASC, salary DESC, name ASC
3434
;
3535
```
3636

37+
## Site Solution
38+
39+
```sql
40+
-- TBD
41+
```
42+
3743
## Notes
3844

3945
TODO
4046

47+
## NB
48+
49+
TBD
50+
4151
Go to [Table of Contents](/README.md#contents)\
4252
Go to [Overview](/README.md)

solutions/007_top_5_artists.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
Write a query to find the top 5 artists whose songs appear most frequently in the Top 10 of the global_song_rank table. Display the top 5 artist names in ascending order, along with their song appearance ranking. If two or more artists have the same number of song appearances, they should be assigned the same ranking, and the rank numbers should be continuous (i.e. 1, 2, 2, 3, 4, 5). [[Full Description](https://datalemur.com/questions/top-fans-rank)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -31,9 +31,19 @@ WHERE artist_rank <= 5
3131
;
3232
```
3333

34+
## Site Solution
35+
36+
```sql
37+
-- TBD
38+
```
39+
3440
## Notes
3541

3642
TODO
3743

44+
## NB
45+
46+
TBD
47+
3848
Go to [Table of Contents](/README.md#contents)\
3949
Go to [Overview](/README.md)

solutions/008_signup_activation_rate.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
New TikTok users sign up with their emails. They confirmed their signup by replying to the text confirmation to activate their accounts. Users may receive multiple text messages for account confirmation until they have confirmed their new account. A senior analyst is interested to know the activation rate of specified users in the emails table. Write a query to find the activation rate. Round the percentage to 2 decimal places. [[Full Description](https://datalemur.com/questions/signup-confirmation-rate)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -24,18 +24,26 @@ SELECT
2424
ROUND(confirmed / (confirmed + not_confirmed), 2) AS confirm_rate
2525
FROM cte
2626
;
27+
```
28+
29+
## Site Solution
2730

31+
```sql
2832
-- DataLemur Solution
2933
SELECT
3034
ROUND(COUNT(texts.email_id)::DECIMAL / COUNT(DISTINCT emails.email_id), 2) AS activation_rate
3135
FROM emails
3236
LEFT JOIN texts ON emails.email_id = texts.email_id AND texts.signup_action = 'Confirmed'
33-
;
37+
;
3438
```
3539

3640
## Notes
3741

3842
* The key to getting the right result is casting the values as decimal, otherwise you'll get `0`.
3943

44+
## NB
45+
46+
TBD
47+
4048
Go to [Table of Contents](/README.md#contents)\
4149
Go to [Overview](/README.md)

solutions/009_supercloud_customer.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Difficulty per Site: Medium
99

1010
A Microsoft Azure Supercloud customer is defined as a customer who has purchased at least one product from every product category listed in the products table. Write a query that identifies the customer IDs of these Supercloud customers. [[Full Description](https://datalemur.com/questions/supercloud-customer)]
1111

12-
## Solution
12+
## Submitted Solution
1313

1414
```sql
1515
-- Submitted Solution
@@ -28,9 +28,19 @@ WHERE ranking = (SELECT COUNT(DISTINCT product_category) FROM products)
2828
;
2929
```
3030

31+
## Site Solution
32+
33+
```sql
34+
-- TBD
35+
```
36+
3137
## Notes
3238

3339
TODO
3440

41+
## NB
42+
43+
TBD
44+
3545
Go to [Table of Contents](/README.md#contents)\
3646
Go to [Overview](/README.md)

solutions/010_odd_and_even_measurements.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Definition:
1515

1616
Within a day, measurements taken at 1st, 3rd, and 5th times are considered odd-numbered measurements, and measurements taken at 2nd, 4th, and 6th times are considered even-numbered measurements. [[Full Description](https://datalemur.com/questions/odd-even-measurements)]
1717

18-
## Solution
18+
## Submitted Solution
1919

2020
```sql
2121
-- Submitted Solution
@@ -41,7 +41,11 @@ FROM cte2
4141
GROUP BY time_day
4242
ORDER BY time_day
4343
;
44+
```
45+
46+
## Site Solution
4447

48+
```sql
4549
-- DataLemur Solution
4650
WITH ranked_measurements AS (
4751
SELECT
@@ -66,5 +70,9 @@ GROUP BY measurement_day;
6670
* DataLemur was able to use one less CTE by using `FILTER`.
6771
* Another difference is the use of `MOD()` vs a `%` arithmatic operator.
6872

73+
## NB
74+
75+
TBD
76+
6977
Go to [Table of Contents](/README.md#contents)\
7078
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)