Hello World!<br>Im stuck with a SQL (SQL Server 2008) query. To sum up, we have a Table \"Teams\" which has two columns, teamID and name. Then we have another Table \"Matches\" that has, among other things, matchID, localTeamID, visitorTeamID,localTeamGoals,visitorTeamGoals....etc etc. So the query requires the following: \"Return the name of the teams, indicating the number of matches played as local, and the number of matches played as visitor, as two different columns, in a single query, not allowed to use Cursors\".<br><br>The problem is, you need the team names, so when you do the join between Matches and Teams on, lets say, localTeamID = teamID, you only get the local matches...so in order to get the visitors aswell...you join again the same teamID with visitorTeamID....but there is my problem, for each local match, i get all the visitors matches...<br><br>How can I obtain the right result like<br><pre>
Team LocalMatches VisitorMatches
Real Madrid 4 5
Manchester 5 4
</pre><br><br>Note that \"sums\" or \"counts\" in the query may differ. <br>Thanks in advance, I hope anyone can help me here. <br><br>Hess
I was also thinking of group by as a solution. Here is a link to the difference between pivot and group by<br><br>http://mattclingan.wordpress.com/2008/02/08/pivot-tables-vs-sum-w-group-by-rollups-vs-cube/<br><br>
I am sure that he means formal engineer, <img alt="\":hihi:\"" src="%5C"> but then again, being an engineer can suck sometimes...maybe he wants out?!?<img alt="\":student:\"" src="%5C"> <img alt="\":drink3:\"" src="%5C"><br><br><div class="\"tbscode_standard_quote_headline\""><img alt="\"Quote\"" src="%5C">Quote from <a href="%5C">Baubbi</a>:</div><div class="\"tbscode_standard_quote\"">\"former\" engineer?</div>
<div class="\"tbscode_standard_quote_headline\""><img alt="\"Quote\"" src="%5C">Quote from <a href="%5C">dalfor</a>:</div><div class="\"tbscode_standard_quote\"">I am sure that he means formal engineer, <img alt="\":hihi:\"" src="%5C"> but then again, being an engineer can suck sometimes...maybe he wants out?!?<img alt="\":student:\"" src="%5C"> <img alt="\":drink3:\"" src="%5C"><br><br><div class="\"tbscode_standard_quote_headline\""><img alt="\"Quote\"" src="%5C">Quote from <a href="%5C">Baubbi</a>:</div><div class="\"tbscode_standard_quote\"">\"former\" engineer?</div></div><br><br>Ty dalfor for correcting me and for correctly explain what I meant to say. And I still dont wanna out. What I want is a bigger salary right now <img alt="\":pc4:\"" src="%5C">