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 |
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2009-03-05 : 00:34:19
|
| I have this table:Program lob attributes sumGlobe Globe Globe1 2Voyager Chat Possible connection rules 1Voyager Chat TC string information 3Voyager Chat Refund arrangement screens 3Voyager Chat Supplementary information 2Voyager Phone Refund arrangement screens 1I need another column that would look like this:Program lob attributes sum sum per lobGlobe Globe Globe1 2 2Voyager Chat Possible connection rules 1 9Voyager Chat TC string information 3 9Voyager Chat Refund arrangement screens 3 9Voyager Chat Supplementary information 2 3Voyager Phone Refund arrangement screens 1 3here's my statement:Select program, lob, attributes, count(attributes) as disputesfrom dbo.disputeattributeswhere attributes <> ' 'group by program, lob, attributes |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-05 : 00:52:39
|
| Can u Explain Briefly and ur expected output |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2009-03-05 : 00:54:01
|
| I want the output to be like this:Program lob attributes sum sum per lobGlobe Globe Globe1 2 2Voyager Chat Possible connection rules 1 9Voyager Chat TC string information 3 9Voyager Chat Refund arrangement screens 3 9Voyager Chat Supplementary information 2 3Voyager Phone Refund arrangement screens 1 3 |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-05 : 00:56:13
|
How did you get the values for sum per lob ?quote: Originally posted by BankOfficerHere I want the output to be like this:Program lob attributes sum sum per lobGlobe Globe Globe1 2 2Voyager Chat Possible connection rules 1 9Voyager Chat TC string information 3 9Voyager Chat Refund arrangement screens 3 9Voyager Chat Supplementary information 2 3Voyager Phone Refund arrangement screens 1 3
|
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2009-03-05 : 00:57:03
|
| that's my problem. I need another column for sum per lob..with those results. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-05 : 01:01:37
|
| if u use sum() for then u will get output asProgram lob attributes sum sum per lobGlobe Globe Globe1 2 2Voyager Chat Possible connection rules 1 9Voyager Chat TC string information 3 9Voyager Chat Refund arrangement screens 3 9Voyager Chat Supplementary information 2 9Voyager Phone Refund arrangement screens 1 1 |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2009-03-05 : 01:03:00
|
| yes, how can i get my desired results? |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-05 : 01:05:09
|
| Is this you are looking for?declare @Sample TABLE( Program varchar(50), lob varchar(50), attributes varchar(50), sum int)insert @Sampleselect 'Globe', 'Globe', 'Globe1', 2union allselect 'Voyager', 'Chat', 'Possible connection rules', 1union allselect 'Voyager', 'Chat', 'TC string information', 3union allselect 'Voyager', 'Chat', 'Refund arrangement screens', 3union allselect 'Voyager', 'Chat', 'Supplementary information', 2union allselect 'Voyager', 'Phone', 'Refund arrangement screens', 1SELECT program, s.lob, attributes,sum,SumPerLob FROM@Sample sJOIN( Select lob, sum(sum) as SumPerLob from @sample where attributes <> ' ' group by lob)tON s.lob=t.lob |
 |
|
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-03-05 : 01:05:24
|
| ur question is not clear |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-05 : 01:05:24
|
| Are u looking for this one:--declare @temp table (Program varchar(32),lob varchar(32), attributes varchar(32), sums int)insert into @tempselect 'Globe' ,'Globe' ,'Globe1', 2 union allselect 'Voyager' ,'Chat', 'Possible connection rules', 1 union all select 'Voyager' ,'Chat', 'TC strin information', 3 union allselect 'Voyager' ,'Chat' ,'Refund arrangement screens', 3 union allselect 'Voyager' ,'Chat' ,'Supplementary information', 2 union allselect 'Voyager' ,'Phone' ,'Refund arrangement screens' ,1select t.Program,t.lob,attributes,sums,sumperlob from @temp tleft join ( select lob,sum(sums) sumperlob from @temp group by lob) t1 on t.lob = t1.lob |
 |
|
|
sridhar.dbe
Starting Member
34 Posts |
Posted - 2009-03-05 : 01:10:33
|
| with d as ( select 'Globe' as 'Program','Globe' as 'lob','Globe1' as 'attributes', 2 as 'sum1' union allselect 'Voyager', 'Chat', 'Possible connection rules',1 union allselect 'Voyager', 'Chat', 'TCstring information',3 union allselect 'Voyager', 'Chat', 'Refund arrangement screens',3 union allselect 'Voyager', 'Chat', 'Supplementary information',2 union allselect 'Voyage'r, 'Phone', 'Refund arrangement screens',1)select *,sum(sum1) over(partition by lob) from d order by lobisk |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2009-03-05 : 02:28:11
|
| that's not possible because I want the attributes to be dynamica |
 |
|
|
|
|
|
|
|