将两列相乘并以新列显示

时间:2015-12-25 12:56:14

标签: mysql sql database

我有3个名为carscarrentrentorder.days的表。我想要的是将cardetail.rentdayrentorder.totalrent相乘,并在SELECT customers.*, cardetail.carname, cardetail.model, cardetail.company, cardetail.color, cardetail.rentday, rentorder.days, rentorder.totalrent FROM rentorder INNER JOIN customers ON customers.custid = rentorder.custid INNER JOIN cardetail ON cardetail.id = rentorder.carid 中显示该值。我无法做到这一点。我怎样才能做到这一点。 请提出任何建议。

SQL

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;


public class event extends Application {


public void start(Stage primaryStage)
{
   HBox pane = new HBox();
   pane.setAlignment(Pos.CENTER);
   Button btOk = new Button("OK");
   Button btCancel = new Button("Cancel");
   OkHandlerClass handler1 = new OkHandlerClass();
   btOk.setOnAction(handler1);
   CancelHandlerClass handler2 = new CancelHandlerClass();
   pane.getChildren().addAll(btOk, btCancel);

   Scene scene = new Scene(pane);
   primaryStage.setTitle("Handle the fucking event");
   primaryStage.setScene(scene);
   primaryStage.show();
 }

 class OkHandlerClass implements EventHandler<ActionEvent>{
    public void handle(ActionEvent e) {
        System.out.println("OK button clicked");
    }
 }
 class CancelHandlerClass implements EventHandler<ActionEvent>{


    public void handle(ActionEvent event) {
       System.out.println("Cancel button clicked");
    }


 }


 public static void main(String[] args) {
    launch(args);
 }



 }

1 个答案:

答案 0 :(得分:3)

只需将rentdaydays相乘即可获得totalrent列表中的计算值Select

试试这个

SELECT customers.*, -- Not sure this is allowed in [Mysql]
       cardetail.carname, 
       cardetail.model, 
       cardetail.company, 
       cardetail.color, 
       cardetail.rentday, 
       rentorder.days, 
       cardetail.rentday * rentorder.days AS totalrent 
FROM   rentorder 
       INNER JOIN customers 
               ON customers.custid = rentorder.custid 
       INNER JOIN cardetail 
               ON cardetail.id = rentorder.carid 

要保存数据,您需要使用update语法

中的Inner Join
update rentorder 
       INNER JOIN customers 
               ON customers.custid = rentorder.custid 
       INNER JOIN cardetail 
               ON cardetail.id = rentorder.carid 
SET
    rentorder.totalrent = cardetail.rentday * rentorder.days