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
 Transact-SQL (2000)
 Help with creating SQL Statement to get data from

Author  Topic 

ricc
Starting Member

16 Posts

Posted - 2005-08-04 : 09:45:30
Hi, I'm having some difficulty creating the SQL Statement for getting some data from a table:

I have the following table of data

__User___Votes___Month

__A_______14______2
__A_______12______3
__A_______17______4
__A_______11______5

__B_______19______2
__B_______12______3
__B_______15______4



I want to beable to pull out the total number of votes a user has had over a period of months.

eg Total up each users users votes for months 4 and 5

that would give:

__User____TotalVotes

___A________28
___B________15

An added complecation is that user B does not have any data for month 5

Any help or pointers would be fanstatic

Many thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-04 : 09:58:29

Select [user],sum(vote) as TotalVotes from yourtable
where month between 4 and 5 group by [user]

Madhivanan

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

- Advertisement -