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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Groupby Distinct

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-08-31 : 14:39:44
I have the following:

select distinct(categorydescription), SUM([account market value]), company from SnapsRaw
group by categorydescription,Company, [account market value]


i get results like this


BAD DATA 1159174.9500 DIOCESE
BAD DATA 1347287.2400 DIOCESE
BAD DATA 1796789.2400 DIOCESE
BAD DATA 1890988.0300 DIOCESE
BAD DATA 1965941.2100 DIOCESE


BAD DATA 2036066.9600 TOUCHPOINT
BAD DATA 6198265.2700 TOUCHPOINT


how can i get it so it just shows

BAD DATA SUM VALUE DIOCESE
BAD DATA SUM VALUE TOUCHPOINT


I realize its probably something easy, but fairly new to all this, once again, help is greatly appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-31 : 14:41:53
Try this:

select categorydescription, SUM([account market value]), company
from SnapsRaw
group by categorydescription, Company

Tara Kizer
Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-08-31 : 14:43:34
WOW, your good, so i cant include the aggregate function in the groupby should be my lesson learned?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-31 : 14:46:14
It just depends on what you want. There was no reason to have it there and there was no reason to have the distinct either.

Tara Kizer
Go to Top of Page
   

- Advertisement -