Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

basic question about totals in sql server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
COHENMARVIN@lycos.com - 29 Jul 2008 21:31 GMT
Suppose I have a table of numbers.  I want to display that table, but
I also want to display the sum of the number in each column as the
last row of the table.  Can I do that?  I know I can do a 'group by'
with aggregate functions, but in this case I wouldn't want to group,
I'd just want a result set whose last row is totals.  One idea I have
is to do a 'union' of two queries, the second query being the 'sum'
query.  Is there an easier way?
(This would be useful in asp.net pages.)
Thanks,
Marv
Aaron Bertrand [SQL Server MVP] - 29 Jul 2008 21:44 GMT
Do you mean

SELECT a, b, c, total = (a + b + c)
FROM table?

If so, there is no magic way to do it... you can drag the columns node from
Object Explorer onto a query window to shorten your work a bit...

A

> Suppose I have a table of numbers.  I want to display that table, but
> I also want to display the sum of the number in each column as the
[quoted text clipped - 6 lines]
> Thanks,
> Marv
Aaron Bertrand [SQL Server MVP] - 29 Jul 2008 22:08 GMT
I mixed up rows and columns.  Yes, after re-reading I think the easiest way
would be a UNION ALL.

On 7/29/08 4:44 PM, in article #hOL8ub8IHA.3480@TK2MSFTNGP03.phx.gbl, "Aaron
Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote:

> Do you mean
>
[quoted text clipped - 16 lines]
>> Thanks,
>> Marv
Plamen Ratchev - 29 Jul 2008 22:14 GMT
Depending on your query, you may be able to use GROUP BY <columns> WITH
ROLLUP. That will add subtotal and total rows for the grouping columns.

Plamen Ratchev
http://www.SQLStudio.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.