diff --git a/.github/workflows/generate-docs.yaml b/.github/workflows/generate-docs.yaml index 2667cba..a90b71d 100644 --- a/.github/workflows/generate-docs.yaml +++ b/.github/workflows/generate-docs.yaml @@ -20,9 +20,9 @@ jobs: build-docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: pipx install poetry - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: { python-version: 3.11, cache: poetry } - run: poetry install --with docs - run: poetry run mkdocs gh-deploy --force diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3d3dda..71d3d10 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- ci: autoupdate_schedule: quarterly - skip: ["poetry-lock", "sourcery", "pylint", "pytest", "coverage-badge"] + skip: ["poetry-lock", "sourcery", "pylint"] repos: - repo: meta @@ -93,21 +93,3 @@ repos: types: ["python"] args: ["-rn", "--rcfile=pyproject.toml"] exclude: "^.*$" # Exclude everything for now - - # Testing and coverage - - repo: local - hooks: - - id: pytest - name: Run unit tests - entry: pytest tests - language: system - pass_filenames: false - always_run: true - exclude: "^.*$" # Exclude everything for now - - id: coverage-badge - name: Generate coverage badge - entry: coverage-badge -o coverage.svg -f - language: system - pass_filenames: false - always_run: true - exclude: "^.*$" # Exclude everything for now diff --git a/coverage.svg b/coverage.svg deleted file mode 100644 index e1f81da..0000000 --- a/coverage.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - coverage - coverage - 28% - 28% - - diff --git a/docs/challenging-sql-problems/problems/silver/suspicious-login-activity.md b/docs/challenging-sql-problems/problems/silver/suspicious-login-activity.md index 473c018..54b10b7 100644 --- a/docs/challenging-sql-problems/problems/silver/suspicious-login-activity.md +++ b/docs/challenging-sql-problems/problems/silver/suspicious-login-activity.md @@ -44,4 +44,4 @@ The solution can be found at: >? TIP: **Hint 2** > -> Use the difference between two `ROW_NUMBER()` functions to create a group for each user and event type. Partition on `user_id` for one and partitioning on both `user_id` and `event_id` for the other, ordering both by `event_id`. +> Use the difference between two `ROW_NUMBER()` functions to create a group for each user and event type. Partition on `user_id` for one and partition on both `user_id` and `event_type` for the other, ordering both by `event_id`. diff --git a/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--snowflake.sql b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--snowflake.sql new file mode 100644 index 0000000..67a6cfb --- /dev/null +++ b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--snowflake.sql @@ -0,0 +1,27 @@ +```sql +with temperatures as ( + select + site_id, + reading_datetime, + temperature, + sum(temperature) over ( + partition by site_id + order by reading_datetime rows between 2 preceding and 2 following + ) as sum_temps + from readings + qualify 5 = count(*) over ( + partition by site_id + order by reading_datetime rows between 2 preceding and 2 following + ) +) + +select + * exclude (sum_temps), + round((sum_temps - temperature) / 4, 4) as average_temperature, + round(100 * (temperature - average_temperature) / temperature, 4) as percentage_increase +from temperatures +where percentage_increase > 10 +order by + site_id, + reading_datetime +``` diff --git a/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--sql-server.sql b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--sql-server.sql index d81d9d8..b71b40b 100644 --- a/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--sql-server.sql +++ b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--sql-server.sql @@ -1,29 +1,16 @@ ```sql -with temps as ( +with temperatures as ( select site_id, reading_datetime, temperature, - ( - avg(temperature) over rows_before_site_reading - + avg(temperature) over rows_after_site_reading - ) / 2 as average_temperature, - ( - count(temperature) over rows_before_site_reading - + count(temperature) over rows_after_site_reading - ) as count_of_rows + (sum(temperature) over rows_around_site_reading - temperature) / 4 as average_temperature, + count(*) over rows_around_site_reading as count_of_rows from readings - window - rows_before_site_reading as ( - partition by site_id - order by reading_datetime - rows between 2 preceding and 1 preceding - ), - rows_after_site_reading as ( - partition by site_id - order by reading_datetime - rows between 1 following and 2 following - ) + window rows_around_site_reading as ( + partition by site_id + order by reading_datetime rows between 2 preceding and 2 following + ) ) select @@ -31,11 +18,11 @@ select reading_datetime, temperature, round(average_temperature, 4) as average_temperature, - round(100.0 * (temperature - average_temperature) / average_temperature, 4) as percentage_increase -from temps + round(100.0 * (temperature - average_temperature) / temperature, 4) as percentage_increase +from temperatures where 1=1 - and count_of_rows = 4 - and (temperature - average_temperature) / average_temperature > 0.1 + and count_of_rows = 5 + and (temperature - average_temperature) / temperature > 0.1 order by site_id, reading_datetime diff --git a/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection.md b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection.md index eb8e0de..ba6e7be 100644 --- a/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection.md +++ b/docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection.md @@ -30,6 +30,11 @@ Some SQL solutions per database are provided below. > --8<-- "docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--duckdb.sql" + +> SUCCESS: **Snowflake** +> +--8<-- "docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--snowflake.sql" + > SUCCESS: **SQL Server** >