关于Sql语句的请教?!·!·##

mailxin 2005-03-11 04:56:48
有表Table,有字段Col_A,Col_A_Value,Col_Type,有记录数分别为
A,A_Value,Type1
A1,A1_Value,Type1
B,B_Value,Type2
B1,B1_Value,Type2
B2,B2_Value,Type2
C,C_Value,Type3
C1,C1_Value,Type3
C2,C2_Value,Type3
C3,C3_Value,Type3
想获得查询结果集
A,A_Value,B,B_Value,C,C_Value
A,A_Value,B,B_Value,C1,C1_Value
A,A_Value,B,B_Value,C2,C2_Value
A1,A1_Value,B,B_Value,C,C_Value
A1,A1_Value,B,B_Value,C1,C1_Value
.....
即按Col_Type分类,获得Type1*Type2*Type3的所有记录
该如何写Sql语句?????????????????????????
...全文
93 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
poonzsp 2005-03-11
  • 打赏
  • 举报
回复
up
dazhu2 2005-03-11
  • 打赏
  • 举报
回复
up
子陌红尘 2005-03-11
  • 打赏
  • 举报
回复
select
A.Col_A ,
A.Col_A_Value,
B.Col_A ,
B.Col_A_Value,
C.Col_A ,
C.Col_A_Value
from
Table A,
Table B,
Table C
where
A.Col_Type = 'Type1'
and
B.Col_Type = 'Type2'
and
C.Col_Type = 'Type3'
order by
A.Col_A,B.Col_A,C.Col_A
xluzhong 2005-03-11
  • 打赏
  • 举报
回复
create function test(@type nvarchar(100))
returns table
as
return(select Col_A,Col_A_Value,id='1' from table where Col_Type=@type)
go

select *
from dbo.test('type1') a
join dbo.test('type2') b
on a.id=b.id
join dob.test('type3') c
on a.id=c.id

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧