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
 General SQL Server Forums
 New to SQL Server Programming
 Group By

Author  Topic 

issammansour
Yak Posting Veteran

51 Posts

Posted - 2007-08-20 : 14:09:17
Hi,

How to use select statement group by with more than one variable at the same time like the following example:

select vno,sum(camt) as camt,sum(damt) as damt
from transact
where year = 2007
group by vno and vtype
order by vno

Thanks


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-20 : 14:10:30
select vno,sum(camt) as camt,sum(damt) as damt
from transact
where year = 2007
group by vno, vtype
order by vno



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-20 : 14:11:49
Or you can have a look in BOOKS ONLINE for the WITH ROLLUP and WITH CUBE keywords.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

issammansour
Yak Posting Veteran

51 Posts

Posted - 2007-08-20 : 14:27:19
thanks
Go to Top of Page

issammansour
Yak Posting Veteran

51 Posts

Posted - 2007-08-20 : 14:34:24
is that mean I cann't add field to select side unless i add it to the group by
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-20 : 14:54:20
Yes,Anything in your select statement that you aren't aggregating(Count, sum,min,max, etc.)
has to be in the group by list

Jim
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-21 : 04:01:59
quote:
Originally posted by issammansour

is that mean I cann't add field to select side unless i add it to the group by


You need to Learn SQL
Read about Group by clause in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -