Foxpro

從 SQL 中的 SELECT 中減去值

  • February 12, 2014

我有以下兩個查詢:

  1. shipManagementInvoiceNetValue:
SELECT IFNULL (SUM (shipManagementInvoice.netto ), 0) AS shipManagementInvoiceNetValue
FROM tckopf AS shipManagementInvoice
WHERE shipManagementInvoice.referenzid = 1
   AND shipManagementInvoice.btyp = 5
  1. shipManagementCreditNoteNetValue:
SELECT IFNULL (SUM (shipManagementCreditNote.netto), 0) AS shipManagementCreditNoteNetValue
FROM tckopf AS shipManagementCreditNote
WHERE shipManagementCreditNote.referenzid = 1
   AND shipManagementCreditNote.btyp = 6

但我需要結果shipManagementInvoiceNetValue - shipManagementCreditNoteNetValue。我使用的HXTT JDBC DBF 驅動程序支持的不僅僅是 SQL92

我怎麼能意識到這一點?

嘗試這個..

SELECT X.shipManagementInvoiceNetValue - Y.shipManagementCreditNoteNetValue
FROM 
(
  SELECT IFNULL (SUM (shipManagementInvoice.netto ), 0) AS shipManagementInvoiceNetValue
  FROM tckopf AS shipManagementInvoice
  WHERE shipManagementInvoice.referenzid = 1
  AND shipManagementInvoice.btyp = 5
)X,
(
  SELECT IFNULL (SUM (shipManagementCreditNote.netto), 0) AS shipManagementCreditNoteNetValue
  FROM tckopf AS shipManagementCreditNote
  WHERE shipManagementCreditNote.referenzid = 1
  AND shipManagementCreditNote.btyp = 6
)Y

引用自:https://dba.stackexchange.com/questions/58673