将一个数据集与另一个数据集进行比较并更新两个数据集

时间:2016-12-30 12:04:09

标签: sql apache-spark-sql

我有两个数据集产品和交付。



<table>
          <tr>
            <th>Delivery_ID</th>
            <th>Count_Record</th> 
            <th>Order_Date</th>        
            <th>Product_Delivery_ID</th>
             <th>Qty_Delivered</th>
          </tr>
          <tr>
            <td>1</td>      
            <td>30</td>
            <td>11/12/2016</td>
            <td>101</td>
            <td>20</td>
          </tr>
           <tr>
            <td>2</td>      
            <td>40</td>
            <td>11/21/2016</td>
            <td>101</td>
            <td>0</td>       
          </tr>
            <tr>
            <td>3</td>      
            <td>20</td>
            <td>11/12/2013</td>
            <td>102</td>
            <td>0</td>        
          </tr>
        </table>
&#13;
&#13;
&#13;

&#13;
&#13;
<table>
          <tr>
            <th>Product_Delivery_ID</th>
            <th>Product_Name</th> 
            <th>Order_Date</th>        
            <th>Qty_Available</th>
          </tr>
          <tr>
            <td>101</td>      
            <td>Product1</td>
            <td>12/11/2016</td>
            <td>10</td>
          </tr>
           <tr>
            <td>101</td>
            <td>Product1</td> 
            <td>11/12/2016</td>
            <td>20</td>        
          </tr>
            <tr>
            <td>102</td>
            <td>Product2</td> 
            <td>12/13/2016</td>
            <td>2</td>        
          </tr>
        </table>
&#13;
&#13;
&#13;

我想将Delivery数据集表的每个记录与Product数据集的每个其他记录进行比较。

交付数据集Count_Record列应通过根据Product数据集中Qty_Available列的可用数量更新Qty_Delivered列来进行均衡。

应在两个数据集中进行更新。即产品数据集Qty_Available 应该减去,并且应该添加交付数据集Qty_Delivered。最终结果应该是这样的。有人能让我知道如何实现这一目标。

&#13;
&#13;
<table>
          <tr>
            <th>Product_Delivery_ID</th>
            <th>Product_Name</th> 
            <th>Order_Date</th>        
            <th>Qty_Available</th>
          </tr>
          <tr>
            <td>101</td>      
            <td>Product1</td>
            <td>12/11/2016</td>
            <td>0</td>
          </tr>
           <tr>
            <td>101</td>
            <td>Product1</td> 
            <td>11/12/2016</td>
            <td>0</td>        
          </tr>
            <tr>
            <td>102</td>
            <td>Product2</td> 
            <td>12/13/2016</td>
            <td>0</td>        
          </tr>
        </table>
&#13;
&#13;
&#13;

&#13;
&#13;
<table>
          <tr>
            <th>Delivery_ID</th>
            <th>Count_Record</th> 
            <th>Order_Date</th>        
            <th>Product_Delivery_ID</th>
             <th>Qty_Delivered</th>
          </tr>
          <tr>
            <td>1</td>      
            <td>30</td>
            <td>11/12/2016</td>
            <td>101</td>
            <td>30</td>
          </tr>
           <tr>
            <td>2</td>      
            <td>40</td>
            <td>11/21/2016</td>
            <td>101</td>
            <td>20</td>       
          </tr>
            <tr>
            <td>3</td>      
            <td>20</td>
            <td>11/12/2013</td>
            <td>102</td>
            <td>2</td>        
          </tr>
        </table>
&#13;
&#13;
&#13;

0 个答案:

没有答案