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 |
spooke
Starting Member
7 Posts |
Posted - 2012-11-24 : 06:17:07
|
Hi guys,I am wanting to get a count of wins for a specific team (my_team), this team name is given by the user that is running the application... As I am only wanting to count the wins I then need to only count the rows where my_score is greater then opp_score.For some reason my query is not working... in my mind it looks correct however that my mind wants and what SQL wants is apparently different... if anyone can help that would be great. Query below."SELECT COUNT(my_team) AS wins FROM matches WHERE my_team=" & team & "AND my_score > opp_score" |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2012-11-24 : 07:30:41
|
my guess is, that team name is defined as text. also the "AND my_score ..." is pushed up against the team name - if this is correct, you're missing the surrounding aposttophes, so your query would be:"SELECT COUNT(my_team) AS wins FROM matches WHERE my_team='" & team & "' AND my_score > opp_score"You could have a nice overview with this query:select my_team ,count(*) as wins from matches where my_score>opp_score group by my_team order by wins desc |
|
|
spooke
Starting Member
7 Posts |
Posted - 2012-11-24 : 08:08:26
|
Thanks, that is working now! |
|
|
|
|
|