Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Method 1:</strong> </p> <pre><code>SELECT (select SUM(quantity) from Sales join Document on Sales.IdDocument = Document.IdDocument where (IdTipoDocumento = 'vco' or IdTipoDocumento = 'vcr') and IdArticulo = '01-00321' and IdListaEmpresa = 1000129) - (select SUM(quantity) from Sales join Document on Sales.IdDocument = Document.IdDocument where IdTipoDocumento = 'dco' and IdArticulo = '01-00321' and IdListaEmpresa = 1000129) </code></pre> <p><strong>Method 2:</strong></p> <pre><code>SELECT SUM(SQ) FROM ( SELECT CASE WHEN (IdTipoDocumento = 'vco' or IdTipoDocumento = 'vcr') THEN SUM(Quantity) WHEN IdTipoDocumento = 'dco' THEN -1*SUM(Quantity) END AS SQ FROM Sales join Document on Sales.IdDocument = Document.IdDocument where (IdTipoDocumento IN ('vco', 'vcr','dco')) and IdArticulo = '01-00321' and IdListaEmpresa = '1000129' GROUP BY IdTipoDocumento) AS T1 </code></pre> <p><strong>Method 3:</strong></p> <pre><code>SELECT SUM(CASE WHEN IdTipoDocumento IN ('vco', 'vcr') THEN Quantity ELSE -1*Quantity END) AS SQ FROM Sales join Document on Sales.IdDocument = Document.IdDocument where (IdTipoDocumento IN ('vco', 'vcr','dco')) and IdArticulo = '01-00321' and IdListaEmpresa = 1000129 </code></pre> <p><strong>Method 3a:</strong></p> <pre><code> SELECT IdListaEmpresa, SUM(CASE WHEN IdTipoDocumento IN ('vco', 'vcr') THEN Quantity ELSE -1*Quantity END) AS SQ FROM Sales join Document on Sales.IdDocument = Document.IdDocument WHERE (IdTipoDocumento IN ('vco', 'vcr','dco')) AND IdArticulo = '01-00321' AND IdListaEmpresa IN (1000129, 1000130, 1,2,3,4,5) GROUP BY IdListaEmpresa </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload