Пожалуйста, проверьте это:
SELECT o1.orderid,
productid,
shipcountry,
quantity,
unitprice,
discount,
case
WHEN discount > 0
THEN unitprice - (unitprice * discount)
ELSE unitprice
END AS price_each,
quantity * (SELECT price_each) AS ttl
FROM orders o1 JOIN OrderDetails o2
ON o1.orderid = o2.orderid
Или может быть сделано как:
SELECT ord_id,productid,shipcountry,quantity,unitprice,discount,price_each, (price_each * quantity) AS ttl FROM
(SELECT o1.orderid AS ord_id,
productid,
shipcountry,
quantity,
unitprice,
discount,
case
WHEN discount > 0
THEN unitprice - (unitprice * discount)
ELSE unitprice
END AS price_each
FROM orders o1 JOIN OrderDetails o2
ON o1.orderid = o2.orderid)
AS VR_table