汇总不同表中的列

时间:2018-10-24 05:29:21

标签: sql sql-server

这是我的数据,

表1:

         STORAGE    HANDLING    TOTAL BILLING 
         -------------------------------------- 
             1300    10900     
                0    10950     
                 0    6000     
                 0    5950     

表2:

 LINER REVENUE 
--------------- 
   1300 
    250 
   3000 
    200 

我需要计算总帐单:

总帐单=存储+处理+线性收入。

有人可以引导我对此进行查询吗?

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助

SELECT h.Storage+h.Handling+j.[Liner Revenue] 
         From(SELECT 
               STORAGE
              ,HANDLING
              ,[TOTAL BILLING]
              ,ROW_NUMBER () over(order by rand()) as p
          FROM [Table 1] )h
          INNER JOIN 
          (SELECT 
               [LINER REVENUE]
              ,ROW_NUMBER () over(order by rand()) as p
          FROM [Table 2] )j
          on h.p=j.p