kmishima16 / praha

0 stars 0 forks source link

データベースモデリング1 回答 #5

Closed kmishima16 closed 6 months ago

kmishima16 commented 6 months ago

お疲れ様です。

データベースモデリング1について回答しました。

以下mdファイルにまとめていますので、課題レビューよろしくお願いします。

テーブル設計 https://github.com/kmishima16/praha/blob/feature/db_modeling_1/回答_データベース構築.md

追加課題(論理モデル、物理モデル) https://github.com/kmishima16/praha/blob/feature/db_modeling_1/回答_論理モデルと物理モデル.md

halki117 commented 6 months ago

遅れてすみません、確認しましたLGTMです!

感想になるんですがここら辺INSERTのVALUEの部分が凝った作りで勉強になります。

-- 注文合計額の登録(クーポン考慮)
INSERT INTO paid_orders (order_id, order_amount)
SELECT 
    o.order_id AS order_id,
    -- クーポン(50円引き or 無料)を考慮して各商品の小計を出す
    SUM(
        CASE 
            WHEN c.id = 1 THEN 0 * o.quantity
            WHEN c.id = 2 THEN (p.price - 50) * o.quantity 
            ELSE p.price * o.quantity
        END
    ) AS total_calc_price
kmishima16 commented 6 months ago

レビューありがとうございます! それではマージします