タグ

ブックマーク / tgk.hatenadiary.org (1)

  • group byの注意点 - 極北データモデリング

    今日、こんな感じのテーブルを作って、毎晩日次売上を月次売上に足しこむバッチを走らせる、という仕事をした。 ●店舗別日次売上 create table daily ( store_id integer not null primary key, -- 店舗ID store_group_id integer not null, -- 店舗が所属する店舗グループID sales bigint not null -- 今日の売上 ); ●店舗別月次売上 create table monthly ( store_id integer not null primary key, store_group_id integer not null, sales bigint not null );やり方を2つ思いついた。 full outer join でヨコに結合して足し算 union でタテ積みして集計

    group byの注意点 - 極北データモデリング
  • 1