返回的结果集应根据类型列连接文本列:
我有一个SQL Server表:
id, type, text
1, 1, C#
2, 1, VB
3, 1, Java
4, 1, JQuery
5, 1, SQL
6, 2, Basic
7, 2, Intermediate
8, 2, Advance
9, 2, Not Applicable
我想返回一个如下所示的结果集:
Result
C#/Basic
C#/Intermediate
C#/Advance
C#/Not Applicable
VB/Basic
VB/Intermediate
VB/Advance
VB/Not Applicable
Java/Basic
Java/Intermediate
Java/Advance
Java/Not Applicable
JQuery/Basic
JQuery/Intermediate
JQuery/Advance
JQuery/Not Applicable
SQL/Basic
SQL/Intermediate
SQL/Advance
SQL/Not Applicable
先谢谢
答案 0 :(得分:2)
W
返回
Declare @Table table (id int, type int, text varchar(50))
Insert Into @Table values
(1, 1, 'C#'),
(2, 1, 'VB'),
(3, 1, 'Java'),
(4, 1, 'JQuery'),
(5, 1, 'SQL'),
(6, 2, 'Basic'),
(7, 2, 'Intermediate'),
(8, 2, 'Advance'),
(9, 2, 'Not Applicable')
Select A.Text+'/'+B.Text
From @Table A
Join @Table B on (A.Type=1 and B.Type=2)
Order By 1