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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please help me to get MySQL

Author  Topic 

niyaz4872
Starting Member

41 Posts

Posted - 2012-08-09 : 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

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 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/
Go to Top of Page
   

- Advertisement -