読み方のヒント
矢印ボタン(または ← → キー)でページを移動できます。
明細の1行の小計は、個数×単価です。
SELECT reservation_id, product_id, quantity, unit_price,
quantity * unit_price AS 小計
FROM reservation_items
ORDER BY reservation_id, product_id;
reservation_id | product_id | quantity | unit_price | 小計
----------------+------------+----------+------------+------
R-0001 | p001 | 1 | 380 | 380
R-0001 | p002 | 2 | 220 | 440
R-0002 | p004 | 3 | 240 | 720
R-0003 | p003 | 4 | 180 | 720
R-0003 | p005 | 2 | 200 | 400
(5 rows)
quantity * unit_price は、行ごとに計算されます。単位は「個×円」で、結果は円です。
| 行 | 計算 | 小計 |
|---|---|---|
R-0001・p001 | 1個×380円 | 380円 |
R-0001・p002 | 2個×220円 | 440円 |
quantity * unit_price は 2×220=440 円で、変わりません。quantity * p.price は 2×240=480 円になります。予約したときの金額は440円です。
3 / 20