In SQL Server 2008 habe ich unter Tabelle Score. Ich möchte Score1 und Score2 zusammen für denselben Schüler zeigen. Der Name und die E-Mail-Kombination identifizieren einen Schüler eindeutig (Name oder E-Mail-Adresse können ebenfalls fehlen, wie Jack und [email protected]). Die erwartete Ausgabe wird als T_Combined angezeigt.T-SQL Datensätze basierend auf Kriterien zusammenführen
Ergebnis
Name Email Score1 Score2
John '[email protected]' 75
Peter '[email protected]' 34
Nina '[email protected]' 45
Joseph '[email protected]' 76
Tom '[email protected]' 43
Sam '[email protected]' 76
Nancy '[email protected]' 12
Tina '[email protected]' 56
John '[email protected]' 98
Peter '[email protected]' 12
Nina '[email protected]' 45
Joseph '[email protected]' 87
Tom '[email protected]' 67
Sam '[email protected]' 99
Nancy '[email protected]' 33
Tina '[email protected]' 23
John '[email protected]' 86
Peter '[email protected]' 56
Nina '[email protected]' 98
Joseph '[email protected]' 78
Tom '[email protected]' 12
Sam '[email protected]' 45
Nancy '[email protected]' 76
Tina '[email protected]' 78
John '[email protected]' 98
Peter '[email protected]' 45
Nina '[email protected]' 76
Joseph '[email protected]' 12
Tom '[email protected]' 84
Sam '[email protected]' 27
Nancy '[email protected]' 54
Tina '[email protected]' 50
Jack 10
'[email protected]' 20
T_Combined
Name Email Score1 Score2
John '[email protected]' 86
Peter '[email protected]' 56
Nina '[email protected]' 98
Joseph '[email protected]' 78
Tom '[email protected]' 43 12
Sam '[email protected]' 76 45
Nancy '[email protected]' 12
Tina '[email protected]' 56
John '[email protected]' 98
Peter '[email protected]' 12
Nina '[email protected]' 45 76
Joseph '[email protected]' 87 12
Tom '[email protected]' 67 84
Sam '[email protected]' 99 27
Nancy '[email protected]' 33 54
Tina '[email protected]' 23 50
Jack 10
'[email protected]' 20
Vielen Dank
Tabelle Score erstellen (Name varchar (20), E-Mail varchar (20), Score1 int, SCORE2 int)
Einfügen in Werte Score (Name, E-Mail, Score1) ('John', 'John @ pluto.com', 75) Werte einfügen (Name, Email, Score1) Werte ('Peter', 'Peter @ pluto.com', 34) Werte eingeben (Name, Email, Score1) ('Nina', '[email protected] ', 45) Werte einfügen (Name, Email, Score1) Werte (' Joseph ',' Joseph @ pluto.com ', 76) Werte einfügen (Name, E-Mail, Bewertung1) (' Tom ',' Tom @ pluto.com ', 43) Werte einfügen (Name, Email, Score1) Werte (' Sam ',' Sam @ pluto.com ', 76) Werte (Name, Email, Score1) einfügen (' Nancy ',' Nancy @ pluto.com ', 12) Einfügen in Score (Name, Email, Score1) Werte (' Tina ',' Tina @ pluto.com ', 56) Einfügen in Score (Name, Email, Score1) Werte ('John', 'John @ mars.com', 98) einfügen in Score (Name, E-Mail, Score1) Werte ('Peter', 'Peter @ mars.com', 12) einfügen in Score (Name, Email, Score1) Werte ('Ni na ',' Nina @ mars.com ', 45) Einfügen in Score (Name, Email, Score1) -Werte (' Joseph ',' Joseph @ mars.com ', 87) Einfügen in Score (Name, Email, Score1) Werte ('Tom', 'Tom @ mars.com', 67) Werte einfügen (Name, Email, Score1) Werte ('Sam', 'Sam @ mars.com', 99) einfügen in Score (Name , E-Mail, Score1) Werte ('Nancy', 'Nancy @ mars.com', 33) Werte ('Tina', 'Tina @ mars.com', 23) einfügen
Einfügen in Score (Name, Email, Score2) -Werte ('John', 'John @ pluto.com', 86) Einfügen in Score (Name, Email, Score2) Werte ('Peter', 'Peter @ pluto. com ', 56) Werte einfügen (Name, E - Mail, Score2) Werte (' Nina ',' Nina @ pluto.com ', 98) einfügen in Score (Name , E-Mail, Score2) Werte ('Joseph', 'Joseph @ pluto.com', 78) Werte eingeben (Name, E-Mail, Bewertung2) Werte ('Tom', 'Tom @ pluto.com', 12) einfügen in Score (Name, E-Mail, Score2) Werte ('Sam', 'Sam @ pluto.com', 45) Werte (Nancy, [email protected], 76) Werte einfügen (Name, Email, Score2) Werte ('Tina', 'Tina @ pluto.com', 78) Werte (Name, E-Mail, Bewertung2) Werte ('John', 'John @ mars .com ', 98) Werte einfügen (Name, E-Mail, Score2) (' Peter ',' Peter @ mars.com ', 45) Werte (Name, E-Mail, Bewertung2) einfügen (' Nina ', 'Nina @ mars.com', 76) Einfügen in Werte Score (Name, Email, Score2) ('Joseph', 'Joseph @ mars.com', 12) Einfügen in Score (Name, Email, Score2) Werte ("Tom", "Tom @ mars.com", 84) Werte einfügen (Name, Email, Score2) Werte ('Sam', 'Sam @ mars.com', 27) Werte eingeben (Name, Email, Score2) ('Nancy', '[email protected] ', 54) Werte (' Tina ',' Tina @ mars.com ', 50) eingeben
Werte einfügen (Name, Score1) (' Jack ', 10) einfügen in Score (Email, Score2) Werte ('Maya @ Mond.com ', 20)
Können Sie Ihre Frage besser formatieren? Wählen Sie die Tabellendaten aus und verwenden Sie Strg-K, um sie als Code zu formatieren. – Rudi