-2

如何在此查询末尾减去两个总和

SELECT T0.[DocNum],T0.[CardCode], T0.[CardName], 
T1.[ItemCode], T1.[Dscription], T1.[Quantity], T1.[Price],T0.[DiscSum], 
T0.[VatSum], T0.[DocTotal], T1.[LineTotal], T0.[DocStatus]

FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry


 select distinct itemcode,CardCode,CardName,DocTotal,LineTotal from RIN1 , ORIN
 Select SUM (linetotal) as ARINVOICE from INV1
 Select SUM (LineTotal) as Credittotal from RIN1
4

2 回答 2

0

您可以将总和保存到变量中,然后减去。

Select SUM (linetotal) INTO SUM_ONE from INV1

Select SUM (LineTotal) INTO SUM_TWO from RIN1

SELECT SUM_ONE - SUM_TWO

请注意,由于您同时标记了 mysql 和 sql-server,因此我的语法可能有点偏离。SQL Server 要求其变量以@ 开头。

于 2013-10-02T16:54:14.270 回答
0

您可以对查询执行以下操作:

select (select) - (select);
于 2013-10-02T17:05:40.723 回答