Centar za edukaciju-BiH



#1 20.08.2018 10:44
Gjoreski Van mreze
Administrator
Registrovan od:02.02.2009
Postovi:1,854


Predmet:Komulativni zbir
Verzija 1
PreuzmiIzvorni kôd (SQL):
  1. SELECT t1.DayCount, t1.Sales, SUM(t2.Sales) AS suma
  2. FROM dbo.Sales t1
  3. INNER JOIN Sales t2 ON t1.DayCount >= t2.DayCount
  4. GROUP BY t1.DayCount, t1.Sales
  5. ORDER BY t1.DayCount

Verzija 2

PreuzmiIzvorni kôd (SQL):
  1. DECLARE @SalesTbl TABLE (DayCount SMALLINT, Sales money, RunningTotal money)
  2.  
  3. DECLARE @DayCount SMALLINT,
  4.         @Sales money,
  5.         @RunningTotal money
  6.  
  7. SET @RunningTotal = 0
  8.  
  9. DECLARE rt_cursor CURSOR
  10. FOR
  11. SELECT DayCount, Sales
  12. FROM tSales
  13. ORDER BY DayCount
  14.  
  15. OPEN rt_cursor
  16.  
  17. FETCH NEXT FROM rt_cursor INTO @DayCount,@Sales
  18.  
  19. WHILE @@FETCH_STATUS = 0
  20.  BEGIN
  21.  SET @RunningTotal = @RunningTotal + @Sales
  22.  INSERT @SalesTbl VALUES (@DayCount,@Sales,@RunningTotal)
  23.  FETCH NEXT FROM rt_cursor INTO @DayCount,@Sales
  24.  END
  25.  
  26. CLOSE rt_cursor
  27. DEALLOCATE rt_cursor
  28.  
  29. SELECT * FROM @SalesTbl
↑  ↓

Stranice (1):1


Sva vremena su GMT +01:00. Trenutno vrijeme: 12: 12 am.