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 |
|
chih
Posting Yak Master
154 Posts |
Posted - 2008-07-27 : 20:25:11
|
| hi everyone,i have a table with columns id,userid,charge,description. I want to display all record and get the total charge at the last row. e.g id userid charge description1 34567 2 item1 2 34568 4 item2 3 34569 7 item3 --------------------Expected resultid userid charge description1 34567 2 item1 2 34568 4 item2 3 34569 7 item3 - - 13 ---------------------------how can i do it? I have tried to use with rollup but the result is not as I expect due to group by issue.Thanks in advance |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-07-27 : 20:37:48
|
| If charge is numeric column, can try this:select id, userid, charge, description from table ...union allselect null, null, sum(charge), null from table ... |
 |
|
|
raghunathan
Starting Member
2 Posts |
Posted - 2008-07-27 : 23:32:46
|
| Please try with compute ---------------------------SELECT id, userid, charge ,description FROM Appropriate_Table ORDER BY useridCOMPUTE sum(charge)------------------- Hope this helps u ... happy coding |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-28 : 00:18:49
|
quote: Originally posted by raghunathan Please try with compute ---------------------------SELECT id, userid, charge ,description FROM Appropriate_Table ORDER BY useridCOMPUTE sum(charge)------------------- Hope this helps u ... happy coding
will it come as a last row along with details if we use COMPUTE? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-28 : 00:36:46
|
No. it is a separate result set KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-28 : 03:52:08
|
quote: Originally posted by khtan No. it is a separate result set KH[spoiler]Time is always against us[/spoiler]
yeah... i knew that. thts why i checked. i think OPs was expecting sum to come in same result set as last row |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-28 : 04:19:38
|
yup. That's what i think also  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-28 : 04:32:27
|
Use GROUP BY WITH ROLLUP E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|
|