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
 Help combining queries

Author  Topic 

barrett777
Starting Member

4 Posts

Posted - 2011-01-28 : 09:05:00
Hi everyone,

I'm very new to SQL programming. I have a table somewhat like this:

Date | Address# | Street Name | Amount of Errors

What I want to do is list the 10 streets with the most errors for all time, in desc order.

So basically I need to add together the amount of errors for each day for each unique address# and street.

For example, these entries:

Date | A# | Street N. | Errors
1/25 | 5 | S Oakdale | 3
1/26 | 5 | S Oakdale | 5
1/25 | 10 | S Oakdale | 5
1/26 | 10 | S Oakdale | 8
1/27 | 10 | S Oakdale | 2

Would return something like this:

A# | Street N. | Errors
10 | S Oakdale | 15
5 | S Oakdale | 5

Hopefully that makes sense. I would also greatly appreciate help on how to do the same, but only counting errors over the last week.

Thanks for your time,
Ben

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-28 : 09:09:44
select [Address#],[Street N.], sum(Errors) as Errors
from your_table
group by [Street N.],[Address#]

and btw. Errors for "5|S Oakdale|" will give 8 and not 5


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-29 : 11:12:56
your explanation and output doesnt match. you're telling you want total for a day but in output you're doing summation irrespective of day as all your dates are different

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

barrett777
Starting Member

4 Posts

Posted - 2011-01-30 : 19:44:35
webfred got the idea, thanks so much :)
Go to Top of Page
   

- Advertisement -