导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

向各位大哥请教一条SQL语句

xin51job 2008-01-11 02:54:44
表bevy
bevy_id bevy_name
1 足球
3 蓝球
表bevyman
bevyman_id bevy_id man_id
1 1 1
2 1 2
3 3 1
1 3 5
当man_id=1时,如何得到
bevy_id man_id
1 2
3 5
谢谢大家
...全文
67 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuedeem 2008-01-11
select * from bevyman where bevy_id in (select bevy_id from bevyman where man_id=1)
回复
jinjazz 2008-01-11
--建立测试环境
set nocount on
create table test(bevyman_id varchar(20),bevy_id varchar(20),man_id varchar(20))
insert into test select '1','1','1'
insert into test select '2','1','2'
insert into test select '3','3','1'
insert into test select '4','3','5'
insert into test select '5','2','3'
go
--测试
select * from test a where exists(select 1 from
test where man_id=1 and bevy_id=a.bevy_id and man_id<>a.man_id)
--删除测试环境
drop table test
set nocount off
回复
xin51job 2008-01-11
谢谢大家,是这样的.
表bevy
bevy_id bevy_name
1 足球
2 蓝球
3 台球
表bevyman
bevyman_id bevy_id man_id
1 1 1
2 1 2
3 3 1
4 3 5
5 2 3
当man_id=1时,如何得到
bevy_id man_id
1 2
3 5
得到与man_id=1相同的bevy_id的另一man_id
回复
free1879 2008-01-11
SELECT bevy_id,man_id
FROM bevyman
WHERE man_id <> 1
回复
-狙击手- 2008-01-11
select a.bevy_id,main_id
from bevyman a
left join bevy b
on a.bevy_id = b.bevy_id
where a.man_id <> 1
回复
kk19840210 2008-01-11
select bevy_id,man_id from bevyman where man_id <> 1
回复
jinjazz 2008-01-11
貌似是select * from bevyman where man_id<>1吧
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告