From 10635054bcc9fd2c2d7d416071ee9ed6d510b018 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 19 Jun 2024 06:57:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20docs:=20fix=20typos=20and?= =?UTF-8?q?=20rearrange=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../challenging-sql-problems.md | 6 +- .../bronze/customer-churn--sample-input.sql | 4 +- .../problems/bronze/customer-churn.md | 7 +- .../problems/bronze/customer-churn.sql | 8 +- .../fibonacci-sequence--sample-output.sql | 18 ++-- .../problems/bronze/fibonacci-sequence.md | 2 +- .../bronze/personalised-customer-emails.sql | 12 +-- ...uspicious-login-activity--sample-input.sql | 18 ++-- .../problems/gold/loan-repayment-schedule.md | 2 +- .../gold/travel-plans--sample-input.sql | 4 +- .../problems/gold/travel-plans.md | 8 +- .../problems/gold/travel-plans.sql | 44 +++++----- .../problems/silver/bus-routes.sql | 4 +- .../problems/silver/decoding-datelist-ints.md | 2 + .../funnel-analytics--sample-output.sql | 16 ++-- .../problems/silver/funnel-analytics.md | 18 ++-- .../problems/silver/mandelbrot-set.md | 4 +- .../predicting-values--sample-input.sql | 2 +- .../problems/silver/region-precipitation.sql | 24 ++--- .../solutions/bronze/fibonacci-sequence.sql | 88 +++++++++---------- .../silver/decoding-datelist-ints--duckdb.sql | 2 +- .../solutions/silver/predicting-values.md | 2 +- .../silver/region-precipitation--duckdb.sql | 2 +- .../region-precipitation--sql-server.sql | 2 +- mkdocs.yml | 6 +- 25 files changed, 154 insertions(+), 151 deletions(-) diff --git a/docs/challenging-sql-problems/challenging-sql-problems.md b/docs/challenging-sql-problems/challenging-sql-problems.md index 66a6c05..be7e5b0 100644 --- a/docs/challenging-sql-problems/challenging-sql-problems.md +++ b/docs/challenging-sql-problems/challenging-sql-problems.md @@ -19,9 +19,9 @@ As long as you know your database features and query patterns, these are fairly 1. [Temperature anomaly detection](problems/bronze/temperature-anomaly-detection.md) 2. [Personalised customer emails](problems/bronze/personalised-customer-emails.md) 3. [Suspicious login activity](problems/bronze/suspicious-login-activity.md) -4. [UK bank holidays](problems/bronze/uk-bank-holidays.md) -5. [Customer churn](problems/bronze/customer-churn.md) -6. [Fibonacci sequence](problems/bronze/fibonacci-sequence.md) +4. [Customer churn](problems/bronze/customer-churn.md) +5. [Fibonacci sequence](problems/bronze/fibonacci-sequence.md) +6. [UK bank holidays](problems/bronze/uk-bank-holidays.md) ### ⚪ Silver Tier diff --git a/docs/challenging-sql-problems/problems/bronze/customer-churn--sample-input.sql b/docs/challenging-sql-problems/problems/bronze/customer-churn--sample-input.sql index bde8795..7352574 100644 --- a/docs/challenging-sql-problems/problems/bronze/customer-churn--sample-input.sql +++ b/docs/challenging-sql-problems/problems/bronze/customer-churn--sample-input.sql @@ -1,8 +1,8 @@ ```sql with user_history(user_id, last_update, activity_history) as ( values - (1, '2024-03-01', 81), - (2, '2024-03-01', 2688), + (1, '2024-03-01', 81), + (2, '2024-03-01', 2688), (3, '2024-03-01', 13144) ) ``` diff --git a/docs/challenging-sql-problems/problems/bronze/customer-churn.md b/docs/challenging-sql-problems/problems/bronze/customer-churn.md index 58cfac4..a9e2009 100644 --- a/docs/challenging-sql-problems/problems/bronze/customer-churn.md +++ b/docs/challenging-sql-problems/problems/bronze/customer-churn.md @@ -105,7 +105,6 @@ We can apply the same logic to the other bits: └-------------- 2024-02-24 (active) ``` -└─ Since there are no more bits on the left, we can assume that the user was inactive on those days. This user is therefore not a churned user since they were active at least once in the last 7 days. @@ -114,7 +113,7 @@ This user is therefore not a churned user since they were active at least once i The `activity_history` for user 2 is `2688`, which in binary is `101010000000`. -We can expand the binary representation to understand the activity again: +We can expand the binary representation to understand the activity: ``` 1 0 1 0 1 0 0 0 0 0 0 0 @@ -133,13 +132,13 @@ We can expand the binary representation to understand the activity again: └------------------------ 2024-02-19 (active) ``` -User 2 _has_ churned user since they were not active in the last 7 days (between `2024-02-24` and `2024-03-01`) but were active at least once in the 7 days before that. +User 2 _has_ churned since they were not active in the last 7 days (between `2024-02-24` and `2024-03-01`) but were active at least once in the 7 days before that. #### User 3 The `activity_history` for user 3 is `13144`, which in binary is `11001101011000`. -We can expand the binary representation to understand the activity again: +Again, we can expand the binary representation to understand the activity: ``` 1 1 0 0 1 1 0 1 0 1 1 0 0 0 diff --git a/docs/challenging-sql-problems/problems/bronze/customer-churn.sql b/docs/challenging-sql-problems/problems/bronze/customer-churn.sql index a2fd25e..afd6dbc 100644 --- a/docs/challenging-sql-problems/problems/bronze/customer-churn.sql +++ b/docs/challenging-sql-problems/problems/bronze/customer-churn.sql @@ -1,15 +1,15 @@ ```sql create table user_history ( - user_id int primary key, - last_update date not null, + user_id int primary key, + last_update date not null, activity_history bigint not null, ); insert into user_history values - (1, '2024-06-01', 1056256), + (1, '2024-06-01', 1056256), (2, '2024-06-01', 907289368), (3, '2024-06-01', 201335032), - (4, '2024-06-01', 9769312), + (4, '2024-06-01', 9769312), (5, '2024-06-01', 246247510), (6, '2024-06-01', 492660983) ; diff --git a/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence--sample-output.sql b/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence--sample-output.sql index ed2cfc2..2640175 100644 --- a/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence--sample-output.sql +++ b/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence--sample-output.sql @@ -1,15 +1,15 @@ ```sql solution(n, f_n) as ( values - (1, 1), - (2, 1), - (3, 2), - (4, 3), - (5, 5), - (6, 8), - (7, 13), - (8, 21), - (9, 34), + (1, 1), + (2, 1), + (3, 2), + (4, 3), + (5, 5), + (6, 8), + (7, 13), + (8, 21), + (9, 34), (10, 55) ) ``` diff --git a/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence.md b/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence.md index e54f787..675c24d 100644 --- a/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence.md +++ b/docs/challenging-sql-problems/problems/bronze/fibonacci-sequence.md @@ -61,4 +61,4 @@ The solution can be found at: >? TIP: **Hint 2** > -> Use the columns `n`, `f_n`, and `f_m` to keep track of the current term, the current Fibonacci number, and the previous Fibonacci number. +> Use the columns `n`, `f_n`, and `f_m` to keep track of the current term, the current Fibonacci number, and the previous Fibonacci number, respectively. diff --git a/docs/challenging-sql-problems/problems/bronze/personalised-customer-emails.sql b/docs/challenging-sql-problems/problems/bronze/personalised-customer-emails.sql index 10347d3..e8957eb 100644 --- a/docs/challenging-sql-problems/problems/bronze/personalised-customer-emails.sql +++ b/docs/challenging-sql-problems/problems/bronze/personalised-customer-emails.sql @@ -1,9 +1,9 @@ ```sql create table customers ( - customer_id int primary key, - full_name varchar not null, - first_name varchar, - last_name varchar, + customer_id int primary key, + full_name varchar not null, + first_name varchar, + last_name varchar, email_address varchar ); insert into customers @@ -25,8 +25,8 @@ values create table customer_relationships ( parent_customer_id int references customers(customer_id), - child_customer_id int references customers(customer_id), - relationship_type varchar not null, + child_customer_id int references customers(customer_id), + relationship_type varchar not null, primary key (parent_customer_id, child_customer_id) ); insert into customer_relationships diff --git a/docs/challenging-sql-problems/problems/bronze/suspicious-login-activity--sample-input.sql b/docs/challenging-sql-problems/problems/bronze/suspicious-login-activity--sample-input.sql index 358a386..abcd15e 100644 --- a/docs/challenging-sql-problems/problems/bronze/suspicious-login-activity--sample-input.sql +++ b/docs/challenging-sql-problems/problems/bronze/suspicious-login-activity--sample-input.sql @@ -1,14 +1,14 @@ ```sql with events(event_id, user_id, event_datetime, event_type) as ( values - (1, 1, '2024-01-01 03:00:00', 'login failed'), - (2, 1, '2024-01-01 03:01:00', 'login failed'), - (3, 1, '2024-01-01 03:02:00', 'login failed'), - (4, 1, '2024-01-01 03:03:00', 'login failed'), - (5, 1, '2024-01-01 03:04:00', 'login failed'), - (6, 1, '2024-01-01 03:05:00', 'login'), - (7, 2, '2024-01-01 10:00:00', 'login'), - (8, 2, '2024-01-01 15:00:00', 'logout'), - (9, 2, '2024-01-01 23:00:00', 'login failed') + (1, 1, '2024-01-01 03:00:00', 'login failed'), + (2, 1, '2024-01-01 03:01:00', 'login failed'), + (3, 1, '2024-01-01 03:02:00', 'login failed'), + (4, 1, '2024-01-01 03:03:00', 'login failed'), + (5, 1, '2024-01-01 03:04:00', 'login failed'), + (6, 1, '2024-01-01 03:05:00', 'login'), + (7, 2, '2024-01-01 10:00:00', 'login'), + (8, 2, '2024-01-01 15:00:00', 'logout'), + (9, 2, '2024-01-01 23:00:00', 'login failed') ) ``` diff --git a/docs/challenging-sql-problems/problems/gold/loan-repayment-schedule.md b/docs/challenging-sql-problems/problems/gold/loan-repayment-schedule.md index cac6204..a4e26e5 100644 --- a/docs/challenging-sql-problems/problems/gold/loan-repayment-schedule.md +++ b/docs/challenging-sql-problems/problems/gold/loan-repayment-schedule.md @@ -17,7 +17,7 @@ > - `repayment_date` as the date of the repayment > - `interest` as the interest component of the repayment > - `principal` as the principal component of the repayment -> - `total` as the total repayment +> - `total` as the total value of the repayment > - `balance` as the outstanding balance _after_ the repayment > > Order the output by `loan_id` and `repayment_number`. diff --git a/docs/challenging-sql-problems/problems/gold/travel-plans--sample-input.sql b/docs/challenging-sql-problems/problems/gold/travel-plans--sample-input.sql index dc5e114..47d15fc 100644 --- a/docs/challenging-sql-problems/problems/gold/travel-plans--sample-input.sql +++ b/docs/challenging-sql-problems/problems/gold/travel-plans--sample-input.sql @@ -14,7 +14,7 @@ routes_schedule( ) as ( values (1, 'train', 'London Gatwick', 'London St Pancras', '09:00:00+00:00', '21:00:00+00:00', '01:00:00', '00:30:00', 12.25), - (2, 'bus', 'London Gatwick', 'London St Pancras', '06:00:00+00:00', '06:00:00+00:00', null, '03:30:00', 8.50) + (2, 'bus', 'London Gatwick', 'London St Pancras', '06:00:00+00:00', '06:00:00+00:00', null, '03:30:00', 8.50) ), routes_timetable( @@ -29,6 +29,6 @@ routes_timetable( values (1, 'boat', 'New York', 'London Gatwick', '2024-01-01 04:30:00-05:00', '2024-01-01 22:00:00+00:00', 179.00), (2, 'plane', 'New York', 'London Gatwick', '2024-01-01 18:00:00-05:00', '2024-01-02 10:45:00+00:00', 125.00), - (3, 'boat', 'London St Pancras', 'Paris', '2024-01-02 13:00:00+00:00', '2024-01-02 14:30:00+01:00', 75.00) + (3, 'boat', 'London St Pancras', 'Paris', '2024-01-02 13:00:00+00:00', '2024-01-02 14:30:00+01:00', 75.00) ) ``` diff --git a/docs/challenging-sql-problems/problems/gold/travel-plans.md b/docs/challenging-sql-problems/problems/gold/travel-plans.md index 91699ba..4b889b9 100644 --- a/docs/challenging-sql-problems/problems/gold/travel-plans.md +++ b/docs/challenging-sql-problems/problems/gold/travel-plans.md @@ -2,9 +2,9 @@ > [!SUCCESS] Scenario > -> You're helping a client plan a trip from New York to Paris, and they want you to find the fastest and cheapest route. +> You're helping a client plan a trip from New York to Paris, and they want you to find the fastest and cheapest routes. > -> They have collected journey information into two tables: +> They have collected journey information for routes that they are happy to take into two tables: > > - `routes_timetable` > - `routes_schedule` @@ -17,7 +17,7 @@ > > Given the tables that your client has provided, find the fastest and cheapest route from New York to Paris, leaving after `2024-01-01 12:00:00-05:00`. > -> Give a minimum of 30 minutes and a maximum of 2 hours for "interchange" time (the time between arrival and departure at the same location). All costs are in the same currency (with no currency specified by the client). +> Give a minimum of 30 minutes and a maximum of 6 hours for "interchange" time, which is the time between arrival and departure at the same location. All costs are in the same currency (with no currency specified by the client). > > The output should have at most two rows (the fastest/cheapest routes, which may be the same route), with the columns: > @@ -50,7 +50,7 @@ The solution can be found at: > | 1 | train | London Gatwick | London St Pancras | 09:00:00 +00:00 | 21:00:00 +00:00 | 01:00:00 | 00:30:00 | 12.25 | > | 2 | bus | London Gatwick | London St Pancras | 06:00:00 +00:00 | 06:00:00 +00:00 | _null_ | 03:30:00 | 8.50 | > -> **Routes Schedule** +> **Routes Timetable** > > | route_id | mode_of_transport | from_location | to_location | departure_datetime | arrival_datetime | cost | > |---------:|:------------------|:------------------|:---------------|:-------------------|:------------------|-------:| diff --git a/docs/challenging-sql-problems/problems/gold/travel-plans.sql b/docs/challenging-sql-problems/problems/gold/travel-plans.sql index c80f5ab..0bbfa80 100644 --- a/docs/challenging-sql-problems/problems/gold/travel-plans.sql +++ b/docs/challenging-sql-problems/problems/gold/travel-plans.sql @@ -1,47 +1,47 @@ ```sql create table routes_schedule ( - schedule_id int primary key, - mode_of_transport varchar not null, - from_location varchar not null, - to_location varchar not null, + schedule_id int primary key, + mode_of_transport varchar not null, + from_location varchar not null, + to_location varchar not null, earliest_departure timetz not null, - latest_departure timetz not null, - frequency time, /* `null` means that it's daily */ - duration time not null, - cost decimal(8, 2) not null, + latest_departure timetz not null, + frequency time, /* `null` means that it's daily */ + duration time not null, + cost decimal(8, 2) not null, ); insert into routes_schedule values (1, 'train', 'London St Pancras', 'London Gatwick', '08:00:00+00:00', '20:00:00+00:00', '01:00:00', '00:30:00', 17.50), (2, 'train', 'London St Pancras', 'London Gatwick', '07:30:00+00:00', '22:30:00+00:00', '02:30:00', '01:15:00', 12.00), - (3, 'bus', 'London St Pancras', 'London Gatwick', '06:15:00+00:00', '06:15:00+00:00', null, '03:30:00', 6.75), - (4, 'bus', 'London St Pancras', 'London Gatwick', '19:30:00+00:00', '19:30:00+00:00', null, '03:30:00', 6.75), + (3, 'bus', 'London St Pancras', 'London Gatwick', '06:15:00+00:00', '06:15:00+00:00', null, '03:30:00', 6.75), + (4, 'bus', 'London St Pancras', 'London Gatwick', '19:30:00+00:00', '19:30:00+00:00', null, '03:30:00', 6.75), (5, 'train', 'London Gatwick', 'London St Pancras', '09:00:00+00:00', '21:00:00+00:00', '01:00:00', '00:30:00', 17.50), (6, 'train', 'London Gatwick', 'London St Pancras', '07:15:00+00:00', '22:15:00+00:00', '02:30:00', '01:15:00', 12.00), - (7, 'bus', 'London Gatwick', 'London St Pancras', '06:00:00+00:00', '06:00:00+00:00', null, '03:30:00', 6.75), - (8, 'bus', 'London Gatwick', 'London St Pancras', '20:00:00+00:00', '20:00:00+00:00', null, '03:30:00', 6.75) + (7, 'bus', 'London Gatwick', 'London St Pancras', '06:00:00+00:00', '06:00:00+00:00', null, '03:30:00', 6.75), + (8, 'bus', 'London Gatwick', 'London St Pancras', '20:00:00+00:00', '20:00:00+00:00', null, '03:30:00', 6.75) ; create table routes_timetable ( - route_id int primary key, - mode_of_transport varchar not null, - from_location varchar not null, - to_location varchar not null, + route_id int primary key, + mode_of_transport varchar not null, + from_location varchar not null, + to_location varchar not null, departure_datetime timestamptz not null, - arrival_datetime timestamptz not null, - cost decimal(8, 2) not null, + arrival_datetime timestamptz not null, + cost decimal(8, 2) not null, ); insert into routes_timetable values - (1, 'boat', 'London St Pancras', 'Paris', '2024-01-01 06:00:00+00:00', '2024-01-01 07:30:00+01:00', 45.00), + (1, 'boat', 'London St Pancras', 'Paris', '2024-01-01 06:00:00+00:00', '2024-01-01 07:30:00+01:00', 45.00), (2, 'plane', 'London Gatwick', 'New York', '2024-01-01 13:05:00+00:00', '2024-01-01 20:55:00-05:00', 158.00), (3, 'plane', 'London Gatwick', 'New York', '2024-01-02 20:40:00+00:00', '2024-01-03 04:30:00-05:00', 147.00), - (4, 'plane', 'London St Pancras', 'Paris', '2024-01-03 07:00:00+00:00', '2024-01-03 08:30:00+01:00', 70.00), + (4, 'plane', 'London St Pancras', 'Paris', '2024-01-03 07:00:00+00:00', '2024-01-03 08:30:00+01:00', 70.00), (5, 'plane', 'Paris', 'New York', '2024-01-02 12:00:00+01:00', '2024-01-02 20:30:00-05:00', 180.00), (6, 'plane', 'New York', 'London Gatwick', '2024-01-01 13:00:00-05:00', '2024-01-02 05:45:00+00:00', 160.00), (7, 'boat', 'New York', 'London Gatwick', '2024-01-01 05:30:00-05:00', '2024-01-01 23:00:00+00:00', 195.00), - (8, 'boat', 'London St Pancras', 'Paris', '2024-01-01 18:00:00+00:00', '2024-01-01 19:30:00+01:00', 95.00), - (9, 'boat', 'London St Pancras', 'Paris', '2024-01-02 14:00:00+00:00', '2024-01-02 15:30:00+01:00', 40.00), + (8, 'boat', 'London St Pancras', 'Paris', '2024-01-01 18:00:00+00:00', '2024-01-01 19:30:00+01:00', 95.00), + (9, 'boat', 'London St Pancras', 'Paris', '2024-01-02 14:00:00+00:00', '2024-01-02 15:30:00+01:00', 40.00), (10, 'plane', 'New York', 'Paris', '2024-01-01 18:00:00-05:00', '2024-01-02 17:45:00+01:00', 279.00) ; ``` diff --git a/docs/challenging-sql-problems/problems/silver/bus-routes.sql b/docs/challenging-sql-problems/problems/silver/bus-routes.sql index bf48cea..3ea8bd8 100644 --- a/docs/challenging-sql-problems/problems/silver/bus-routes.sql +++ b/docs/challenging-sql-problems/problems/silver/bus-routes.sql @@ -1,8 +1,8 @@ ```sql create table bus_stops ( - bus_id int, + bus_id int, from_stop varchar, - to_stop varchar, + to_stop varchar, primary key (bus_id, from_stop) ); insert into bus_stops diff --git a/docs/challenging-sql-problems/problems/silver/decoding-datelist-ints.md b/docs/challenging-sql-problems/problems/silver/decoding-datelist-ints.md index 4e06e23..839285a 100644 --- a/docs/challenging-sql-problems/problems/silver/decoding-datelist-ints.md +++ b/docs/challenging-sql-problems/problems/silver/decoding-datelist-ints.md @@ -10,6 +10,8 @@ > > The number of rows to show in the output should be the number of days in the `activity_history` column for the user with the most days. > +> Just like in the [customer churn](../bronze/customer-churn.md) problem, the `last_update` column will always have the same date for all users. +> > The output should have a single row per day with the columns: > > - `active_date` as the date of the activity, starting from the `last_update` date diff --git a/docs/challenging-sql-problems/problems/silver/funnel-analytics--sample-output.sql b/docs/challenging-sql-problems/problems/silver/funnel-analytics--sample-output.sql index 5b5651c..e2f7944 100644 --- a/docs/challenging-sql-problems/problems/silver/funnel-analytics--sample-output.sql +++ b/docs/challenging-sql-problems/problems/silver/funnel-analytics--sample-output.sql @@ -1,13 +1,13 @@ ```sql solution(cohort, stage, mortgages, step_rate, total_rate) as ( values - ('2024-01', 'full application', 1, 100, 100), - ('2024-01', 'decision', 1, 100, 100), - ('2024-01', 'documentation', 1, 100, 100), - ('2024-01', 'valuation inspection', 1, 100, 100), - ('2024-01', 'valuation made', 1, 100, 100), - ('2024-01', 'valuation submitted', 1, 100, 100), - ('2024-01', 'solicitation', 1, 100, 100), - ('2024-01', 'funds released', 0, 0, 0) + ('2024-01', 'full application', 1, 100.00, 100.00), + ('2024-01', 'decision', 1, 100.00, 100.00), + ('2024-01', 'documentation', 1, 100.00, 100.00), + ('2024-01', 'valuation inspection', 1, 100.00, 100.00), + ('2024-01', 'valuation made', 1, 100.00, 100.00), + ('2024-01', 'valuation submitted', 1, 100.00, 100.00), + ('2024-01', 'solicitation', 1, 100.00, 100.00), + ('2024-01', 'funds released', 0, 0.00, 0.00) ) ``` diff --git a/docs/challenging-sql-problems/problems/silver/funnel-analytics.md b/docs/challenging-sql-problems/problems/silver/funnel-analytics.md index 78389f4..760b71a 100644 --- a/docs/challenging-sql-problems/problems/silver/funnel-analytics.md +++ b/docs/challenging-sql-problems/problems/silver/funnel-analytics.md @@ -29,6 +29,8 @@ > - `step_rate` as the percentage of mortgages that reached the stage compared to the previous stage > - `total_rate` as the percentage of mortgages that reached the stage compared to the first stage > +> Round the `step_rate` and `total_rate` to two decimal places. +> > Note that each cohort should have _all_ the stages, even if there are no mortgages that reached that stage -- the `mortgages` column should be `0` in that case. > > Order the output by `cohort` and _the `stage` order_ (e.g. `full application` should come before `decision`, and so on). @@ -64,14 +66,14 @@ The solution can be found at: > > | cohort | stage | mortgages | step_rate | total_rate | > |:--------|:---------------------|----------:|----------:|-----------:| -> | 2024-01 | full application | 1 | 100 | 100 | -> | 2024-01 | decision | 1 | 100 | 100 | -> | 2024-01 | documentation | 1 | 100 | 100 | -> | 2024-01 | valuation inspection | 1 | 100 | 100 | -> | 2024-01 | valuation made | 1 | 100 | 100 | -> | 2024-01 | valuation submitted | 1 | 100 | 100 | -> | 2024-01 | solicitation | 1 | 100 | 100 | -> | 2024-01 | funds released | 0 | 0 | 0 | +> | 2024-01 | full application | 1 | 100.00 | 100.00 | +> | 2024-01 | decision | 1 | 100.00 | 100.00 | +> | 2024-01 | documentation | 1 | 100.00 | 100.00 | +> | 2024-01 | valuation inspection | 1 | 100.00 | 100.00 | +> | 2024-01 | valuation made | 1 | 100.00 | 100.00 | +> | 2024-01 | valuation submitted | 1 | 100.00 | 100.00 | +> | 2024-01 | solicitation | 1 | 100.00 | 100.00 | +> | 2024-01 | funds released | 0 | 0.00 | 0.00 | > --8<-- "docs/challenging-sql-problems/problems/silver/funnel-analytics--sample-output.sql" diff --git a/docs/challenging-sql-problems/problems/silver/mandelbrot-set.md b/docs/challenging-sql-problems/problems/silver/mandelbrot-set.md index 0b9f101..7fcbc94 100644 --- a/docs/challenging-sql-problems/problems/silver/mandelbrot-set.md +++ b/docs/challenging-sql-problems/problems/silver/mandelbrot-set.md @@ -6,7 +6,7 @@ > [!QUESTION] > -> Plot an image of the Mandelbrot set. +> Plot an image of the [Mandelbrot set](https://en.wikipedia.org/wiki/Mandelbrot_set). > > Start with a 51x51 grid of points ranging from -2 to 2 on both the x and y axes. A sample of some points in the grid are: > @@ -51,7 +51,7 @@ The solution can be found at: - [mandelbrot-set.md](../../solutions/silver/mandelbrot-set.md) -A worked example is provided below to help illustrate the loan calculations. +A worked example is provided below to help illustrate the Mandelbrot set calculations. --- diff --git a/docs/challenging-sql-problems/problems/silver/predicting-values--sample-input.sql b/docs/challenging-sql-problems/problems/silver/predicting-values--sample-input.sql index f88f498..899dc3d 100644 --- a/docs/challenging-sql-problems/problems/silver/predicting-values--sample-input.sql +++ b/docs/challenging-sql-problems/problems/silver/predicting-values--sample-input.sql @@ -1,7 +1,7 @@ ```sql with datasets(dataset_1__x, dataset_1__y, dataset_2__x, dataset_2__y) as ( values - (1, 2.00, 1, 9.12), + (1, 2.00, 1, 9.12), (2, 4.00, 3, 31.18), (3, 6.00, 5, 55.27), (4, 8.00, 7, 61.12) diff --git a/docs/challenging-sql-problems/problems/silver/region-precipitation.sql b/docs/challenging-sql-problems/problems/silver/region-precipitation.sql index b7444bd..c7f4ff1 100644 --- a/docs/challenging-sql-problems/problems/silver/region-precipitation.sql +++ b/docs/challenging-sql-problems/problems/silver/region-precipitation.sql @@ -1,18 +1,18 @@ ```sql create table precipitation ( - grid_id varchar primary key, - pr_january numeric(14, 9), - pr_february numeric(14, 9), - pr_march numeric(14, 9), - pr_april numeric(14, 9), - pr_may numeric(14, 9), - pr_june numeric(14, 9), - pr_july numeric(14, 9), - pr_august numeric(14, 9), + grid_id varchar primary key, + pr_january numeric(14, 9), + pr_february numeric(14, 9), + pr_march numeric(14, 9), + pr_april numeric(14, 9), + pr_may numeric(14, 9), + pr_june numeric(14, 9), + pr_july numeric(14, 9), + pr_august numeric(14, 9), pr_september numeric(14, 9), - pr_october numeric(14, 9), - pr_november numeric(14, 9), - pr_december numeric(14, 9) + pr_october numeric(14, 9), + pr_november numeric(14, 9), + pr_december numeric(14, 9) ); insert into precipitation values diff --git a/docs/challenging-sql-problems/solutions/bronze/fibonacci-sequence.sql b/docs/challenging-sql-problems/solutions/bronze/fibonacci-sequence.sql index 1f756ee..dc0ee8c 100644 --- a/docs/challenging-sql-problems/solutions/bronze/fibonacci-sequence.sql +++ b/docs/challenging-sql-problems/solutions/bronze/fibonacci-sequence.sql @@ -1,50 +1,50 @@ ```sql solution(n, f_n) as ( values - (1, 1), - (2, 1), - (3, 2), - (4, 3), - (5, 5), - (6, 8), - (7, 13), - (8, 21), - (9, 34), - (10, 55), - (11, 89), - (12, 144), - (13, 233), - (14, 377), - (15, 610), - (16, 987), - (17, 1597), - (18, 2584), - (19, 4181), - (20, 6765), - (21, 10946), - (22, 17711), - (23, 28657), - (24, 46368), - (25, 75025), - (26, 121393), - (27, 196418), - (28, 317811), - (29, 514229), - (30, 832040), - (31, 1346269), - (32, 2178309), - (33, 3524578), - (34, 5702887), - (35, 9227465), - (36, 14930352), - (37, 24157817), - (38, 39088169), - (39, 63245986), - (40, 102334155), - (41, 165580141), - (42, 267914296), - (43, 433494437), - (44, 701408733), + (1, 1), + (2, 1), + (3, 2), + (4, 3), + (5, 5), + (6, 8), + (7, 13), + (8, 21), + (9, 34), + (10, 55), + (11, 89), + (12, 144), + (13, 233), + (14, 377), + (15, 610), + (16, 987), + (17, 1597), + (18, 2584), + (19, 4181), + (20, 6765), + (21, 10946), + (22, 17711), + (23, 28657), + (24, 46368), + (25, 75025), + (26, 121393), + (27, 196418), + (28, 317811), + (29, 514229), + (30, 832040), + (31, 1346269), + (32, 2178309), + (33, 3524578), + (34, 5702887), + (35, 9227465), + (36, 14930352), + (37, 24157817), + (38, 39088169), + (39, 63245986), + (40, 102334155), + (41, 165580141), + (42, 267914296), + (43, 433494437), + (44, 701408733), (45, 1134903170) ) ``` diff --git a/docs/challenging-sql-problems/solutions/silver/decoding-datelist-ints--duckdb.sql b/docs/challenging-sql-problems/solutions/silver/decoding-datelist-ints--duckdb.sql index 3251054..6bdd240 100644 --- a/docs/challenging-sql-problems/solutions/silver/decoding-datelist-ints--duckdb.sql +++ b/docs/challenging-sql-problems/solutions/silver/decoding-datelist-ints--duckdb.sql @@ -5,7 +5,7 @@ axis(active_date, max_, step) as ( select (select last_update from user_history limit 1), (select max(log2(activity_history)) from user_history), - 1 as step + 1 union all select active_date - 1, max_, step + 1 from axis diff --git a/docs/challenging-sql-problems/solutions/silver/predicting-values.md b/docs/challenging-sql-problems/solutions/silver/predicting-values.md index d045b6c..34aad5d 100644 --- a/docs/challenging-sql-problems/solutions/silver/predicting-values.md +++ b/docs/challenging-sql-problems/solutions/silver/predicting-values.md @@ -16,7 +16,7 @@ Regardless of the database, the result set should look like: | 17 | 11.5 | 11.5 | 11.5 | 11.5 | | 18 | 12.0 | 12.0 | 12.0 | 12.0 | -This is one of the interesting things about Anscombe's quartet (and is the reason Anscombe created it): the four datasets have the same summary statistics, but look very different when plotted! +This is one of the interesting things about Anscombe's quartet (and is the reason Anscombe created it): the four datasets have the same line of best fit, but look very different when plotted!
Expand for the DDL diff --git a/docs/challenging-sql-problems/solutions/silver/region-precipitation--duckdb.sql b/docs/challenging-sql-problems/solutions/silver/region-precipitation--duckdb.sql index 7fa7c7e..46a8e19 100644 --- a/docs/challenging-sql-problems/solutions/silver/region-precipitation--duckdb.sql +++ b/docs/challenging-sql-problems/solutions/silver/region-precipitation--duckdb.sql @@ -30,7 +30,7 @@ average_precipitation as ( select split_part(grid_id, '-', 1) as region, split_part(grid_id, '-', 2) as location, - grouping(region, location) as group_id, /* 0 - region, location; 1 - region; 3 - total */ + grouping(region, location) as group_id, /* 0 - region & location; 1 - region; 3 - total */ avg(precipitation) as average_precipitation from region_by_month group by rollup (region, location) diff --git a/docs/challenging-sql-problems/solutions/silver/region-precipitation--sql-server.sql b/docs/challenging-sql-problems/solutions/silver/region-precipitation--sql-server.sql index 14ae000..b90b65c 100644 --- a/docs/challenging-sql-problems/solutions/silver/region-precipitation--sql-server.sql +++ b/docs/challenging-sql-problems/solutions/silver/region-precipitation--sql-server.sql @@ -49,7 +49,7 @@ average_precipitation as ( select region, location, - grouping_id(region, location) as group_id, /* 0 - region, location; 1 - region; 3 - total */ + grouping_id(region, location) as group_id, /* 0 - region & location; 1 - region; 3 - total */ avg(precipitation) as average_precipitation from region_by_month group by rollup (region, location) diff --git a/mkdocs.yml b/mkdocs.yml index b5057cc..938c2e6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -79,9 +79,9 @@ nav: - challenging-sql-problems/problems/bronze/temperature-anomaly-detection.md # window functions - challenging-sql-problems/problems/bronze/personalised-customer-emails.md # string similarity - challenging-sql-problems/problems/bronze/suspicious-login-activity.md # window functions (gaps and islands) - - challenging-sql-problems/problems/bronze/uk-bank-holidays.md # unpivot and unnest - challenging-sql-problems/problems/bronze/customer-churn.md # bit-shifting - challenging-sql-problems/problems/bronze/fibonacci-sequence.md # recursive CTE + - challenging-sql-problems/problems/bronze/uk-bank-holidays.md # unpivot and unnest - ⚪ Silver Tier: - challenging-sql-problems/problems/silver/funnel-analytics.md # custom axis - challenging-sql-problems/problems/silver/bannable-login-activity.md # window functions (gaps and islands, range between) @@ -99,8 +99,9 @@ nav: - challenging-sql-problems/solutions/bronze/temperature-anomaly-detection.md - challenging-sql-problems/solutions/bronze/personalised-customer-emails.md - challenging-sql-problems/solutions/bronze/suspicious-login-activity.md - - challenging-sql-problems/solutions/bronze/uk-bank-holidays.md + - challenging-sql-problems/solutions/bronze/customer-churn.md - challenging-sql-problems/solutions/bronze/fibonacci-sequence.md + - challenging-sql-problems/solutions/bronze/uk-bank-holidays.md - ⚪ Silver Tier: - challenging-sql-problems/solutions/silver/funnel-analytics.md - challenging-sql-problems/solutions/silver/bannable-login-activity.md @@ -109,7 +110,6 @@ nav: - challenging-sql-problems/solutions/silver/region-precipitation.md - challenging-sql-problems/solutions/silver/predicting-values.md - challenging-sql-problems/solutions/silver/mandelbrot-set.md - - challenging-sql-problems/solutions/silver/customer-churn.md - challenging-sql-problems/solutions/silver/customer-sales-running-totals.md - 🟡 Gold Tier: - challenging-sql-problems/solutions/gold/loan-repayment-schedule.md