我目前正在处理Java应用程序的收据,但似乎无法在屏幕上得到总和。什么时候使用以下查询,我在PHPMyAdmin中获得了总和,但似乎无法在Java中找到它。我只是无法打印它,因为Java告诉我我尝试的所有列名都是错误的。有谁知道如何解决这一问题?
如果您想要更多的代码,我可以提供,但可以肯定的是查询中有错误,Java无法读出。帮助将不胜感激。
String sql = "SELECT sum((`barorder_drink`.`quantity` * `drink`.`price`)) + sum((`kitchenorder_dish`.`quantity` * `dish`.`price`))"
+ "FROM `barorder`, `barorder_drink`, `drink`, `kitchenorder`, `kitchenorder_dish`, `dish`, `restaurantorder`"
+ "WHERE `barorder`.`restaurantOrderId` = `restaurantorder`.`id`"
+ "AND `kitchenorder`.`restaurantOrderId` = `restaurantorder`.`id`"
+ "AND `barorder_drink`.`barorderId` = `barorder`.`id`"
+ "AND `barorder_drink`.`drinkId` = `drink`.`id`"
+ "AND `kitchenorder_dish`.`kitchenOrderId` = `kitchenorder`.`id`"
+ "AND `kitchenorder_dish`.`dishId` = `dish`.`id`"
+ "AND `restaurantorder`.`id` = '" + ID + "' ;";
最佳答案
将您的总和作为val并像这样获得该值
String sql = "SELECT sum(myattributes) AS val";
当你想得到结果时
int som = getInt("val");