22/04/2008

Quantidade acumulada, valor acumulado, mensal how to

   1.
      SELECT
   2.
      case when t6.itemname IS NULL then ´Total de Produtos´
   3.
      else t6.itemname
   4.
      end AS Produto,
   5.
      sum(T0.Quantity) AS ´Quantidade´,sum(T0.LineTotal) AS ´Valor Total´,´Month Quantity´ AS ´Quantidade Acumulada´, ´Month Total´ AS ´Acumulado do Mes´  FROM  [dbo&93;.&91;INV1&93; T0  INNER  JOIN &91;dbo&93;.&91;OINV&93; T1  ON  T1.DocEntry = T0.DocEntry INNER  JOIN &91;dbo&93;.&91;INV12&93; T4  ON  T4.DocEntry = T1.DocEntry  
   6.
      LEFT JOIN OHEM T5 ON T5.Empid = T1.Ownercode
   7.
      INNER JOIN OITM T6 ON T6.Itemname = T0.Dscription AND T1.DocDate BETWEEN ´2008-04-15´ AND ´2008-04-15´ AND T1.DocEntry NOT IN ( SELECT dnf1.BaseRef FROM OINV dnf INNER JOIN INV1 dnf1 ON dnf.DocEntry = dnf1.DocEntry
   8.
                                                  WHERE dnf.SeqCode = 1 AND dnf1.BaseType = 13) AND t0.cfopcode <> 6152 AND T1.DocEntry NOT IN ( SELECT dnf1.BaseRef FROM ORIN dnf INNER JOIN RIN1 dnf1 ON dnf.DocEntry = dnf1.DocEntry
   9.
                                                  WHERE dnf.SeqCode = 1 AND dnf1.BaseType = 13)
  10.
      GROUP BY t6.itemname



Como eu faco uma quantidade e valor vendido mensalmente de cada produto nessa query como o campo mostra?


Artarian