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 |
sqldbaa
Starting Member
32 Posts |
Posted - 2007-12-18 : 05:30:01
|
Hi All,I am new to SQL programming, i have only a fair knowledge on sql programmin.So, I apologies for any silly questions-I have a Table1 which containsC1-acountidC2-dateC3-grossamount(postivie and negative decimal values)C4-netamountTable2C1-groupidC2-accountidTable 3 C1-groupidC2-groupnameI need create a store procedure to retrieve the following on a single table1. top 10 losers of the day i.e. 10 AccountIDs with the greatest negative Grossamount for the dayNOTE:These 10 AccountIDs may be sam or differing each day2.sum of Netamount for each AccountIDs listed in STEP 1 since the beginning of the month.NOTE:These 10 AccountIDs may be same or differing each day and each day sum of netamount should be from beginning of the month till current date.3.Sum of Netamount for the last 5 days for each accountids in STEP1The result set must contain the columns as belowC1-accountidC2-dateC3-net loss for 10 losers on the current date since the beginning of the monthC4-Sum of Net for last 5 days C5-groupnamePlease help me.Below is the script that i have written, without calculating the sum (select top 10 a.date, a.accountid, a.gross, a.net, c.groupname from GBSys_Sum_EOD ajoin server2.dbname.dbo.table2 b on a.accontid=b.accounit=idjoin server2.dbname.dbo.Table3 c on b.groupid=c.groupidwhere date> getdate()-1and gross< (floor(-00.00)) order by gross)Thanks in advance. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
|
|
|
|