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
 summary query

Author  Topic 

aaroniac
Starting Member

2 Posts

Posted - 2007-01-18 : 14:15:23
I have a table which contains a sports schedule:
team1_id,team2_id,result1,result2

result1 is for team1_id
result2 is for team2_id

I want to run a query to get summarize the two id fields with their assoiciated results:
For Example the dataset might look like this:
row 1 - id1=20,id2=30,result1=1,result2=3
row 2 - id1=30,id2=20,result1=2,result2=2
row 3 - id1=20,id2=40,result1=3,result2=1
row 4 - id1=40,id2=20,result1=1,result2=3

how do I build the query to merge the ids and thier respective results into one countable dataset

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-18 : 14:34:17
Hard to tell without some sample data that builds up the expected output you provided.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

aaroniac
Starting Member

2 Posts

Posted - 2007-01-18 : 15:04:30
Here is some data - the result1 goes with the id1 and the result2 goes with the id2 - the ids with the same numbers are the same team just in different columns with their own respective result. I need the output to be just two columns - id and result. then I can push the data into a pivot query which I already have working.

id1 id2 result1 result2
52 22 1 2
23 24 2 2
25 26 1 3
27 28 3 1
29 30 2 1
30 28 1 1
29 27 4 2
26 24 2 3
25 23 1 3
22 52 2 1
52 23 3 3
22 24 2 1
25 27 3 3
26 28 1 2
29 30 1 1
30 27 1 1
29 28 1 2
26 23 2 3
25 24 1 1
22 52 3 3
52 24 1 2
22 23 1 1
25 28 2 1
26 27 3 1
29 30 3 2
30 26 2 3
29 25 1 3
28 24 2 2
27 23 2 1
22 52 2 1
52 25 1 3
22 26 2 2
23 28 3 1
24 27 1 3
29 30 2 2


Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-01-18 : 15:46:29
select id1, result1
from yourtable
union all
select id2, result2
from yourtable

- Jeff
Go to Top of Page
   

- Advertisement -