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.

 All Forums
 Other Forums
 MS Access
 Counting a sum of several rows

Author  Topic 

keripukki
Starting Member

1 Post

Posted - 2005-06-07 : 15:20:46
Is it possible to count a sum of several rows with just one SQL command?

For example table like this:

column1|column2
---------------
50 | text
3 | text
18 | text


I have tried doing it with this kind of SQL command, but it didn't work:
SELECT DISTINCT SUM(column1) AS [colsum], column2 FROM table
GROUP BY column1, column2;


For me that just gives me all rows. It SHOULD give me this kind of result: 61 | text

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2005-06-07 : 15:31:56
IF column2 is not equal your statement will return your example.

GROUP BY column1, column2

If you need the sum of column1 with each of column2

Set nocount on
Declare @column1 int

Select @column1 = Sum(column1)
From yourtable

Select @column1 as sumofcolumn1, Column2
From yourtable

Jim
Users <> Logic
Go to Top of Page

Bee-Z
Starting Member

6 Posts

Posted - 2005-06-20 : 10:56:31
quote:
Originally posted by keripukki


SELECT DISTINCT SUM(column1) AS [colsum], column2 FROM table
GROUP BY column1, column2;





SELECT DISTINCT SUM(column1) AS [colsum], column2 FROM table
GROUP BY column2
Go to Top of Page
   

- Advertisement -