gpt4 book ai didi

mysql - 从MYSQL中的2个不同表计算数量和价格

转载 作者:行者123 更新时间:2023-11-29 10:50:47 24 4
gpt4 key购买 nike

我有两个表,订单表(用户用来添加订单并计算)和产品,其中包含某些产品的单位价格。理论上,当用户按下计算按钮时,应该发生的情况是用户输入的数量将乘以他们所销售产品的成本。该查询可以在 mysql 控制台上运行,因此这与我尝试将其输入文本字段的方式有关。

以下是我的查询。

public void calculateOrder(ActionEvent event){

String total = totalBox.getText();

String queryUpdate="UPDATE ordertable o JOIN product p ON p.productID = o.productID set o.total = o.amount * p.cost";
String updateBox="SELECT total FROM ordertable";
try{

query=c.prepareStatement(queryUpdate);
query=c.prepareStatement(updateBox);
query.setString(1, total);
//query.setString(2, productID);
query.execute();


query.close();
rs.close();

Alert confirmation = new Alert(Alert.AlertType.CONFIRMATION, "Calculated");

confirmation.show();

}

catch(SQLException e){

System.out.println(e);
}

}

下面是错误。java.sql.SQLException:参数索引超出范围(1 > 参数数量,即 0)。

最佳答案

我认为您的查询有问题。如果我没记错的话,嵌套查询中 o.quantity 是未知的。尝试按如下方式重新格式化:

UPDATE ordertable o 
INNER JOIN products p
ON p.productionID = o.productionID
set o.cost = o.quantity * p.price

关于mysql - 从MYSQL中的2个不同表计算数量和价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43768757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com