相互扣除两个表的值并乘以结果

时间:2018-02-05 11:38:26

标签: mysql sql

我需要从SellingPrice中扣除InclusiveTax以获取NETSellingPrice中的新值。然后将NETSellingprice乘以QTY以获得NETValue。 继承人我拥有的和结果。 请协助。

选择

ST_SalesMixTransactions_RealTimeFeed.InternalMenuLinkItemNumber,ST_SalesMixTransactions_RealTimeFeed.SiteNumber,ST_SalesMixTransactions_RealTimeFeed.OrderMode,ST_SalesMixTransactions_RealTimeFeed.InclusiveTax,ST_SalesMixTransactions_RealTimeFeed.SellingPrice,COUNT(ST_SalesMixTransactions_RealTimeFeed.InternalMenuLinkItemNumber) AS QTY
from ST_SalesMixTransactions_RealTimeFeed
where BusinessDate between '2017-06-27 00:00:00.000' and '2017-07-03 00:00:00.000' and
      SiteNumber='1001006' and 
      InternalMenuLinkItemNumber='1003471' and 
      ST_SalesMixTransactions_RealTimeFeed.OrderMode='2'
group by ST_SalesMixTransactions_RealTimeFeed.InternalMenuLinkItemNumber,ST_SalesMixTransactions_RealTimeFeed.SiteNumber,ST_SalesMixTransactions_RealTimeFeed.OrderMode,ST_SalesMixTransactions_RealTimeFeed.SellingPrice,ST_SalesMixTransactions_RealTimeFeed.InclusiveTax

到目前为止的结果:

InternalMenuLinkItemNumber|1003471
SiteNumber|1001006
OrderMode|2
InclusiveTax|1.830
SellingPrice|14.900
QTY|28

我在寻找什么:

InternalMenuLinkItemNumber| 1003471
SiteNumber| 1001006
OrderMode| 2
InclusiveTax| 1.830
SellingPrice| 14.900
QTY| 28
NETSellingPrice| ???
NETValue| ???

1 个答案:

答案 0 :(得分:0)

尝试在您的选择查询之上添加以下代码。

    Select *,
            (SellingPrice-InclusiveTax) NETSellingPrice,
            (SellingPrice-InclusiveTax)*QTY NETValue 
from (
      your select Statement
     ) A