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 |
|
dang12
Starting Member
12 Posts |
Posted - 2008-11-03 : 05:30:34
|
| Hi,I have the following query:SELECT TOP(100) Tags.TagText, TaggedBrand.BrandId, TaggedBrand.[Count]FROM Tags, TaggedBrand WHERE Tags.TagId = TaggedBrand.TagId AND TaggedBrand.BrandId = '113c56d6-7273-4037-981f-df58d7e0ac9d'Which returns:TagText BrandId Countnice 113C56D6-7273-4037-981F-DF58D7E0AC9D 1chocolate 113C56D6-7273-4037-981F-DF58D7E0AC9D 2chocolate 113C56D6-7273-4037-981F-DF58D7E0AC9D 1My question is, how can I get it to return a sum of the count column?I.e:TagText BrandId Countnice 113C56D6-7273-4037-981F-DF58D7E0AC9D 1chocolate 113C56D6-7273-4037-981F-DF58D7E0AC9D 3many thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 05:33:31
|
| [code]SELECT TOP(100) Tags.TagText, TaggedBrand.BrandId, SUM(TaggedBrand.[Count]) AS CountFROM Tags, TaggedBrand WHERE Tags.TagId = TaggedBrand.TagId AND TaggedBrand.BrandId = '113c56d6-7273-4037-981f-df58d7e0ac9d'GROUP BY Tags.TagText, TaggedBrand.BrandIdORDER BY ....[/code]also you need to order on some field whithout which top 100 is meaningless |
 |
|
|
dang12
Starting Member
12 Posts |
Posted - 2008-11-03 : 05:36:09
|
| Thanks! - that's exactly what I needed! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 06:09:23
|
Cheers |
 |
|
|
|
|
|