SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please help me to get MySQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

niyaz4872
Starting Member

Iran
38 Posts

Posted - 08/09/2012 :  01:48:37  Show Profile  Reply with Quote
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  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000