diff --git a/Docker.ipynb b/Docker.ipynb index ef2094a..c2cb26d 100644 --- a/Docker.ipynb +++ b/Docker.ipynb @@ -41,23 +41,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# 3. VsCodeからコンテナにアクセス\n", - "VsCodeからコンテナにアクセスを行います(画面は変わったように見えないかもしれないですが変わっています)。\n", - "\n", - "慣れている方は、business_sql_courseフォルダ内でdocker-compose up -d でも問題ありません\n", + "# MetaBaseにアクセスして、初期設定を行う\n", "\n", - "以下の画像のボタンからbusiness_sql_courseフォルダを選択します\n", + "ターミナルで\n", "\n", - "![図1.2 VsCodeからコンテナにリモート接続します](images/docker-remote.png)\n", + "docker-compose up -d\n", "\n", - "![図1.2 VsCodeからコンテナにリモート接続します](images/remote_open.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MetaBaseにアクセスして、初期設定を行う\n", "起動まで時間がかかりますが、5分ほどしたら\n", "\n", "http://localhost:3000\n", diff --git a/docker-compose.yml b/docker-compose.yml index 0eb01dc..2727322 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,5 +17,6 @@ services: - ./data/postgres-data:/var/lib/postgresql/data - ./posgreinit:/docker-entrypoint-initdb.d ports: - - 5432:5432 + - 5434:5434 + command: -p 5434 container_name: "db" \ No newline at end of file diff --git a/env b/env index 953bc82..12bd624 100644 --- a/env +++ b/env @@ -2,7 +2,7 @@ MB_DB_FILE=/metabase-data/metabase.db MB_DB_TYPE=postgres MB_DB_DBNAME=metabase -MB_DB_PORT=5432 +MB_DB_PORT=5434 MB_DB_USER=postgres MB_DB_PASS=password MB_DB_HOST=postgres-mb diff --git a/sql/select.sql b/sql/section4_select.sql similarity index 100% rename from sql/select.sql rename to sql/section4_select.sql diff --git a/sql/analysis.sql b/sql/section5_analysis.sql similarity index 91% rename from sql/analysis.sql rename to sql/section5_analysis.sql index 3994be2..d705a06 100644 --- a/sql/analysis.sql +++ b/sql/section5_analysis.sql @@ -45,6 +45,19 @@ with hoge as ( FROM orders ) peke ) +, +base_data as ( +select + product_id, + sa_month, + sum(total) as total +from hoge +where + product_id in(1) +group by product_id,sa_month +order by sa_month +) + select product_id , sa_month @@ -53,15 +66,29 @@ select order by sa_month rows between 5 preceding and current row ) moving_avg -from hoge +from base_data # lag関数/lead関数 +# lag(total,2)のようにする事で、2つ前のデータを取得することも可能です with hoge as ( select * from ( SELECT product_id,total,to_char(created_at, 'YYYY-MM') AS sa_month FROM orders ) peke ) +, +base_data as ( +select + product_id, + sa_month, + sum(total) as total +from hoge +where + product_id in(1) +group by product_id,sa_month +order by sa_month +) + select product_id , sa_month @@ -70,7 +97,7 @@ select partition by product_id order by sa_month ) as lagss -from hoge ; +from base_data ; ## 演習:lag関数を使って売上の先回比を出してみましょう with hoge as ( @@ -79,6 +106,18 @@ with hoge as ( FROM orders ) peke ) +, +base_data as ( +select + product_id, + sa_month, + sum(total) as total +from hoge +where + product_id in(1) +group by product_id,sa_month +order by sa_month +) select product_id @@ -91,7 +130,7 @@ select partition by product_id order by sa_month ) as last_month_ratio -from hoge ; +from base_data ; # roll up/cube/ @@ -106,7 +145,6 @@ select from hoge group by rollup(sa_month,product_id) - # ヒストグラムを書いてみよう # 単純にグラフを書いてみる diff --git a/sql/science.sql b/sql/section6_science.sql similarity index 100% rename from sql/science.sql rename to sql/section6_science.sql