Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
niyaz4872
Starting Member
41 Posts |
Posted - 2012-08-09 : 01:48:37
|
| I have a table With the following fieldsgroupid ,sanadid,money1,1,1002,2,2003,1,300Please help me to get MySQLgroupid,sanadid,money,mandeh1,1,100,1003,1,300,4002,2,200,200mandeh=(if(groupid=groupid) then mandeh=(money+mondeh(index-1))) |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-08-09 : 03:27:23
|
| These are MICROSOFT SQL SERVER specific forums. Still if i want to do same in SQL Server, I will do it as followingDECLARE @temp TABLE (groupid int,sanadid int,mmoney int)INSERT INTO @tempSELECT 1,1,100 UNION ALLSELECT 2,2,200 UNION ALLSELECT 3,1,300SELECT groupid, sanadid,mmoney, ISNULL(mmoney +( SELECT top 1 mmoney FROM @temp WHERE groupid < OuterTable.groupid AND sanadid = OuterTable.sanadid order by groupid desc ),mmoney) AS RunningSumFROM @temp OuterTable ORDER BY sanadid,groupid--------------------------http://connectsql.blogspot.com/ |
 |
|
|
|
|
|
|
|