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 |
senenami
Starting Member
1 Post |
Posted - 2007-06-30 : 21:15:20
|
Hi,I've the following query:select F_Mode, Issue_Count, Sum(Issue_Count) as IssueSum, milestone from rpt_fact_ParetosGroup By F_Mode having milestone = 'SDS'Sample Data:F_Mode Issue_Count milestoneFail1 5 SDSFail2 6 SDSIf the above query is executed, the resultset is:Fail1 5 5 SDSFail2 6 6 SDSQuestion: I'm not getting the SUM of Issue_Count. I agree that I'm using F_Mode as Group By and hence the result. But if I use milestone as Group By I won't get all the F_Mode in the result set.I'm looking for a result like this:Fail1 5 11 SDSFail2 6 11 SDSHow can I achievce this?Thanks in advance,SD |
|
mageshks
Yak Posting Veteran
59 Posts |
Posted - 2007-07-01 : 00:23:39
|
Hope this would give you the desired resultdeclare @IssueSum intselect @IssueSum=sum(Issue_Count) from rpt_fact_Paretoswhere milestone = 'SDS'select F_Mode, Issue_Count,@IssueSum as IssueSum , milestone from rpt_fact_ParetosGroup By F_Mode,Issue_Count,milestone having milestone = 'SDS' |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2007-07-01 : 04:17:10
|
[code]SELECT F_Mode ,Issue_Count ,IssueSum = ( SELECT SUM(Issue_Count) FROM rpt_fact_Paretos iFP WHERE iFP.milestone = oFP.milestone) ,milestoneFROM rpt_fact_Paretos oFPWHERE milestone = 'SDS'[/code]-- If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime. |
|
|
|
|
|
|
|