另一个表中的列使用SQL

时间:2017-07-24 17:01:05

标签: sql insert

我正在学习使用SQL。我有两个表Table1和Table2。我需要从Table1中获取三列,例如A,B,C,并将它们添加为table2上的A,B和C.还使用table2上的C列对列D和E执行算术运算。 我试过了 插入表2(A,B,C) 从表1中选择(A,B,C)。  现在我如何对表2中的D列和E列进行算术计算。它就像这个C * 5一样 和c * 10为E 任何帮助在这里非常感谢

1 个答案:

答案 0 :(得分:0)

我认为这就是你想要的:

<!DOCTYPE html>
<html lang="en" ng-app="ngTodo">
<head>
    <meta charset="UTF-8">
    
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/font-awesome-4.7.0/font-awesome-4.7.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">
    <link href="style.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.js">
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.11/ngStorage.min.js"></script>
    <script src="script.js"></script>
</head>
<body>
    <div class="container-fluid" ng-controller="mainController">
        <!-- navbar top starts here -->
        <nav class="navbar navbar-default navbar-fixed-top">
          <div class="container-fluid">
              <div class="row">
                  <div class="col-sm-2">
                    <div class="navbar-header">
                        <a class="navbar-brand" href="#">
                            <img  width="40px" alt="Todo App Icon" class="img-circle img-responsive" src="assets/icon/icon.jpg">
                        </a>
                    </div>  
                  </div>
                  <div class="col-sm-8">
                      <h2 class="text-center">Today's Todo List</h2>
                  </div>
                  <div class="col-sm-2">
                    <input type="text" placeholder="search..." ng-model="query" class="search-todo-list">
                  </div>
              </div>
          </div>
        </nav>
        <!-- navbar top ends here -->
        <!-- content section starts here -->
        <div class="row">
            <div class="col-sm-12 content">
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3 empty-todo-list-message" ng-if="todoArray.length == 0">
                        <div class="panel panel-default ">
                          <div class="panel-body">
                            <h1><strong>Your Todo List is EMPTY</strong></h1>
                          </div>
                        </div>
                    </div>
                    <!-- item starts here -->
                    <div class="col-sm-6 col-sm-offset-3 todo-item" ng-repeat="todo in todoArray | filter : query" ng-animate=" 'animate' ">
                        <div class="panel panel-default ">
                          <div class="panel-heading text-center">
                            <h3><strong>{{ todo.title + " : "  }}</strong></h3>  
                          </div>
                          <div class="panel-body">
                            <strong>{{ todo.details}}</strong>
                          </div>
                          <div class="panel-footer text-center">
                            <button ng-click="removeTodo($index)"><i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>
                            delete</button>
                          </div>
                        </div>
                    </div>
                    <!-- item ends here -->
                </div>
            </div>
        </div>
        <!-- content section ends here -->
        <!-- navbar bottom starts here -->
        <nav class="navbar navbar-default navbar-fixed-bottom">
          <div class="container-fluid">
            <div class="row">
                <div class="col-sm-4">
                    <input type="text" placeholder="Add Todo Item" required ng-model="newTodo.name" >
                </div>
                <div class=" col-sm-4">
                    <input type="text" placeholder="Add Todo Item Details" required  ng-model="newTodo.details">
                </div>
                <div class=" col-sm-2">
                    <button ng-click="addTodo(newTodo)" ><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;&nbsp;Add ToDo</button>
                </div>
            </div>
          </div>
        </nav>
        <!-- navbar bottom ends here -->
    </div>
</body>
</html>

您可以考虑使用视图而不是表:

insert into Table2 (A,B,C,D,E)
select A,B,C,5*C,10*C from Table1

除非你在谓词中使用D和E,否则不应该有太多的性能损失。