各カートの合計金額を計算するために、商品とカートのテーブルを結合しています。ここに私のSQL文があります:
String sql = "SELECT p.productID, p.productName, p.productPrice, c.quantity, p.productPrice * c.quantity as new_unit_price, SUM(p.productPrice * c.quantity) AS totalPrice"
+ " FROM sm_product p INNER JOIN sm_cart c "
+ "ON p.productID = c.productID"
+ " WHERE c.custName = '" + custName + "'";
カート テーブルの数量と製品テーブルの製品価格を乗算して、new_unit_price という名前の列を導き出しました。次に、派生列 new_unit_price を使用して、カート内のすべてのアイテムの価格を合計します。次の方法で、データベースの列からデータを取得します。
double subItemTotal = rs.getDouble("new_unit_price");
double totalPrice = rs.getDouble("totalPrice");
私の new_unit_price は機能します。しかし、残念ながら、私の合計は機能しません。まだ0です。派生列の値を合計する方法を知っている人はいますか? 前もって感謝します。