在内部连接上乘以两列

时间:2017-07-06 21:28:12

标签: sql

需要帮助。

我想将两列相乘并将结果显示为一个新列(totalQty)。 TotalQty =(ITY00.CMPITQTY * MPOS_GP_InvTransaction.Quantity)

我如何实现这一目标?

Select 
    MPOS_GP_InvTransaction.id, 
    MPOS_GP_InvTransaction.[Type], 
    MPOS_GP_InvTransaction.Vendor, 
    MPOS_GP_InvTransaction.Currency,ITY00.CMPTITNM,
    MPOS_GP_InvTransaction.BatchId, 
    MPOS_GP_InvTransaction.UserId, 
    MPOS_GP_InvTransaction.ItemNo,
    MPOS_GP_InvTransaction.SiteId,
    ITY00.CMPITQTY,
    MPOS_GP_InvTransaction.Quantity,
    MPOS_GP_InvTransaction.IntegrationFlag
From DB_37788.dbo.MPOS_GP_InvTransaction 
INNER JOIN TWCL.dbo.ITY00 ON ITY00.ITEMNMBR=MPOS_GP_InvTransaction.ItemNo
Where (MPOS_GP_InvTransaction.ItemNo  like '%-GTYR%' ) 
OR (MPOS_GP_InvTransaction.ItemNo  like '%-JKOP%' ) 
And (MPOS_GP_InvTransaction.SiteId  IN('MM-DC-ZZQW','MM-DC-TTYR') )
And (MPOS_GP_InvTransaction.IntegrationFlag = 0 )

1 个答案:

答案 0 :(得分:2)

SELECT MPOS_GP_InvTransaction.id,
       MPOS_GP_InvTransaction.Type,
       MPOS_GP_InvTransaction.Vendor,
       MPOS_GP_InvTransaction.Currency,
       ITY00.CMPTITNM,
       MPOS_GP_InvTransaction.BatchId,
       MPOS_GP_InvTransaction.UserId,
       MPOS_GP_InvTransaction.ItemNo,
       MPOS_GP_InvTransaction.SiteId,
       ITY00.CMPITQTY,
       MPOS_GP_InvTransaction.Quantity,
       MPOS_GP_InvTransaction.IntegrationFlag,
      ITY00.CMPITQTY * MPOS_GP_InvTransaction.Quantity AS TotalQty
FROM DB_37788.dbo.MPOS_GP_InvTransaction
     INNER JOIN TWCL.dbo.ITY00 ON ITY00.ITEMNMBR = MPOS_GP_InvTransaction.ItemNo
WHERE(MPOS_GP_InvTransaction.ItemNo LIKE '%-GTYR%')
     OR (MPOS_GP_InvTransaction.ItemNo LIKE '%-JKOP%')
     AND (MPOS_GP_InvTransaction.SiteId IN('MM-DC-ZZQW', 'MM-DC-TTYR'))
     AND (MPOS_GP_InvTransaction.IntegrationFlag = 0);