From 2e54f5050ec5091b8b35f83a39cf949fa259a568 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 7 Jul 2024 09:06:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20fix:=20correct=20supply=20?= =?UTF-8?q?chain=20network=20sales=20and=20add=20data=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../problems/gold/supply-chain-network.md | 2 +- .../problems/gold/supply-chain-network.sql | 18 ++++++------ .../solutions/gold/supply-chain-network.md | 27 ++++++++++++++++- .../solutions/gold/supply-chain-network.sql | 29 +++++++++++++++++++ 4 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 docs/challenging-sql-problems/solutions/gold/supply-chain-network.sql diff --git a/docs/challenging-sql-problems/problems/gold/supply-chain-network.md b/docs/challenging-sql-problems/problems/gold/supply-chain-network.md index 082cd42..e8aad45 100644 --- a/docs/challenging-sql-problems/problems/gold/supply-chain-network.md +++ b/docs/challenging-sql-problems/problems/gold/supply-chain-network.md @@ -59,7 +59,7 @@ The solution can be found at: - [supply-chain-network.md](../../solutions/gold/supply-chain-network.md) -A worked example is provided below to help illustrate the "shuffling" within the locations. +A worked example is provided below to help illustrate the stock movement within the locations. --- diff --git a/docs/challenging-sql-problems/problems/gold/supply-chain-network.sql b/docs/challenging-sql-problems/problems/gold/supply-chain-network.sql index 0d69331..7d7153c 100644 --- a/docs/challenging-sql-problems/problems/gold/supply-chain-network.sql +++ b/docs/challenging-sql-problems/problems/gold/supply-chain-network.sql @@ -67,22 +67,22 @@ values ('2024-01-02 07:12:21'::timestamp, 6, 1001, 2), ('2024-01-02 09:51:01'::timestamp, 7, 1001, 4), ('2024-01-02 10:55:42'::timestamp, 8, 1001, 9), - ('2024-01-02 11:21:10'::timestamp, 7, 1001, 19), - ('2024-01-02 15:02:20'::timestamp, 7, 1001, 1), - ('2024-01-02 16:18:00'::timestamp, 7, 1001, 1), - ('2024-01-02 18:47:13'::timestamp, 7, 1001, 9), + ('2024-01-02 11:21:10'::timestamp, 6, 1001, 19), + ('2024-01-02 15:02:20'::timestamp, 6, 1001, 1), + ('2024-01-02 16:18:00'::timestamp, 6, 1001, 1), + ('2024-01-02 18:47:13'::timestamp, 6, 1001, 9), ('2024-01-02 19:15:12'::timestamp, 8, 1001, 5), ('2024-01-02 20:38:01'::timestamp, 6, 1001, 14), - ('2024-01-03 07:00:27'::timestamp, 7, 1001, 13), + ('2024-01-03 07:00:27'::timestamp, 6, 1001, 3), ('2024-01-03 08:56:40'::timestamp, 6, 1001, 1), - ('2024-01-03 09:40:07'::timestamp, 6, 1001, 14), + ('2024-01-03 09:40:07'::timestamp, 6, 1001, 4), ('2024-01-03 10:21:06'::timestamp, 7, 1001, 4), - ('2024-01-03 12:31:10'::timestamp, 6, 1001, 10), + ('2024-01-03 12:31:10'::timestamp, 7, 1001, 6), ('2024-01-03 15:56:56'::timestamp, 8, 1001, 5), ('2024-01-03 17:49:04'::timestamp, 7, 1001, 12), - ('2024-01-03 18:02:34'::timestamp, 6, 1001, 1), + ('2024-01-03 18:02:34'::timestamp, 6, 1001, 12), ('2024-01-03 20:19:42'::timestamp, 7, 1001, 7), - ('2024-01-03 20:28:00'::timestamp, 6, 1001, 8), + ('2024-01-03 20:28:00'::timestamp, 8, 1001, 15), ('2024-01-04 13:07:02'::timestamp, 7, 1001, 24), ('2024-01-04 14:03:39'::timestamp, 8, 1001, 16) ; diff --git a/docs/challenging-sql-problems/solutions/gold/supply-chain-network.md b/docs/challenging-sql-problems/solutions/gold/supply-chain-network.md index 20eb924..b2a75f2 100644 --- a/docs/challenging-sql-problems/solutions/gold/supply-chain-network.md +++ b/docs/challenging-sql-problems/solutions/gold/supply-chain-network.md @@ -10,7 +10,32 @@ Regardless of the database, the result set should look like: -(to be added) +| stock_date | store_id | supplier_id | stock_volume | stock_proportion | +| :--------- | -------: | ----------: | -----------: | ---------------: | +| 2024-01-01 | 6 | 1 | 0 | 0.00 | +| 2024-01-01 | 6 | 2 | 10 | 100.00 | +| 2024-01-01 | 7 | 1 | 0 | 0.00 | +| 2024-01-01 | 7 | 2 | 0 | 0.00 | +| 2024-01-01 | 8 | 1 | 0 | 0.00 | +| 2024-01-01 | 8 | 2 | 0 | 0.00 | +| 2024-01-02 | 6 | 1 | 0 | 0.00 | +| 2024-01-02 | 6 | 2 | 9 | 100.00 | +| 2024-01-02 | 7 | 1 | 6 | 54.55 | +| 2024-01-02 | 7 | 2 | 5 | 45.45 | +| 2024-01-02 | 8 | 1 | 0 | 0.00 | +| 2024-01-02 | 8 | 2 | 1 | 100.00 | +| 2024-01-03 | 6 | 1 | 14 | 41.18 | +| 2024-01-03 | 6 | 2 | 20 | 58.82 | +| 2024-01-03 | 7 | 1 | 0 | 0.00 | +| 2024-01-03 | 7 | 2 | 2 | 100.00 | +| 2024-01-03 | 8 | 1 | 1 | 6.25 | +| 2024-01-03 | 8 | 2 | 15 | 93.75 | +| 2024-01-04 | 6 | 1 | 34 | 57.63 | +| 2024-01-04 | 6 | 2 | 25 | 42.37 | +| 2024-01-04 | 7 | 1 | 3 | 100.00 | +| 2024-01-04 | 7 | 2 | 0 | 0.00 | +| 2024-01-04 | 8 | 1 | 15 | 100.00 | +| 2024-01-04 | 8 | 2 | 0 | 0.00 |
Expand for the DDL diff --git a/docs/challenging-sql-problems/solutions/gold/supply-chain-network.sql b/docs/challenging-sql-problems/solutions/gold/supply-chain-network.sql new file mode 100644 index 0000000..9b305c0 --- /dev/null +++ b/docs/challenging-sql-problems/solutions/gold/supply-chain-network.sql @@ -0,0 +1,29 @@ +```sql +solution(stock_date, store_id, supplier_id, stock_volume, stock_proportion) as ( + values + ('2024-01-01'::date, 6, 1, 0, 0.00), + ('2024-01-01'::date, 6, 2, 10, 100.00), + ('2024-01-01'::date, 7, 1, 0, 0.00), + ('2024-01-01'::date, 7, 2, 0, 0.00), + ('2024-01-01'::date, 8, 1, 0, 0.00), + ('2024-01-01'::date, 8, 2, 0, 0.00), + ('2024-01-02'::date, 6, 1, 0, 0.00), + ('2024-01-02'::date, 6, 2, 9, 100.00), + ('2024-01-02'::date, 7, 1, 6, 54.55), + ('2024-01-02'::date, 7, 2, 5, 45.45), + ('2024-01-02'::date, 8, 1, 0, 0.00), + ('2024-01-02'::date, 8, 2, 1, 100.00), + ('2024-01-03'::date, 6, 1, 14, 41.18), + ('2024-01-03'::date, 6, 2, 20, 58.82), + ('2024-01-03'::date, 7, 1, 0, 0.00), + ('2024-01-03'::date, 7, 2, 2, 100.00), + ('2024-01-03'::date, 8, 1, 1, 6.25), + ('2024-01-03'::date, 8, 2, 15, 93.75), + ('2024-01-04'::date, 6, 1, 34, 57.63), + ('2024-01-04'::date, 6, 2, 25, 42.37), + ('2024-01-04'::date, 7, 1, 3, 100.00), + ('2024-01-04'::date, 7, 2, 0, 0.00), + ('2024-01-04'::date, 8, 1, 15, 100.00), + ('2024-01-04'::date, 8, 2, 0, 0.00) +) +```