Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions Docker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
46 changes: 42 additions & 4 deletions sql/analysis.sql → sql/section5_analysis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -70,7 +97,7 @@ select
partition by product_id
order by sa_month
) as lagss
from hoge ;
from base_data ;

## 演習:lag関数を使って売上の先回比を出してみましょう
with hoge as (
Expand All @@ -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
Expand All @@ -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/

Expand All @@ -106,7 +145,6 @@ select
from hoge
group by rollup(sa_month,product_id)


# ヒストグラムを書いてみよう

# 単純にグラフを書いてみる
Expand Down
File renamed without changes.