Sayfayı Yazdır | Pencereyi Kapat

How can i do this query by pure sql ?

Nereden Yazdırıldığı: Datakent
Kategori: Diğer bölümler
Forum Adı: Microsoft SQL Server
Forum Tanımlaması: Microsoft SQL Server ile ilgili soru / sorun ve paylaşım bölümü
URL: http://forum.datakent.com/forum_posts.asp?TID=2027
Tarih: 25.Nisan.2024 Saat 07:43


Konu: How can i do this query by pure sql ?
Mesajı Yazan: murat turan
Konu: How can i do this query by pure sql ?
Mesaj Tarihi: 18.Aralik.2010 Saat 17:57

I have a table below

 first      second  
-------     ----------  
100        0  
200        0  
0           400  

I want to get below result

 first      second      result  
-------     ---------- ----------  
100        0            100  
200        0            300  
0           400         -100  

As you can see that result parameter is sum of previous (first-sum) How can i write such a query ?

MYSQL solution is very simple, but simple solutions are looking for Microsoft Sql Server.

set @result =0;  
select first, second, @result := @result + first - second as result  
from tablo;   

results

first  second  result    

100    0       100   
200    0       300   
0      400     -100

alıntı >> stackoverflow.com (soruyu soran : Talat Eri)
 
 
bu tür bir durum için MS SQL Alternatifleri [ My SQL kadar keskin olmasada :)  ]
 
http://www.sqlteam.com/article/calculating-running-totals - http://www.sqlteam.com/article/calculating-running-totals


-------------
http://www.kasatakip.com - Kasa Takip  |  http://www.caritakip.com - Cari Takip  |  http://www.evraktakip.com - Evrak Takip  |  http://www.etasqlmobil.com - ETA SQL Mobil



Sayfayı Yazdır | Pencereyi Kapat