| Author |
Topic  |
|
|
niyaz4872
Starting Member
Iran
38 Posts |
Posted - 08/09/2012 : 01:48:37
|
I have a table With the following fields groupid ,sanadid,money 1,1,100 2,2,200 3,1,300
Please help me to get MySQL groupid,sanadid,money,mandeh 1,1,100,100 3,1,300,400 2,2,200,200
mandeh=(if(groupid=groupid) then mandeh=(money+mondeh(index-1)))
|
|
|
lionofdezert
Aged Yak Warrior
Pakistan
864 Posts |
Posted - 08/09/2012 : 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 following
DECLARE @temp TABLE (groupid int,sanadid int,mmoney int)
INSERT INTO @temp SELECT 1,1,100 UNION ALL SELECT 2,2,200 UNION ALL SELECT 3,1,300
SELECT 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 RunningSum FROM @temp OuterTable ORDER BY sanadid,groupid
-------------------------- http://connectsql.blogspot.com/ |
 |
|
| |
Topic  |
|
|
|