sql server 2005 创建表的sql语句

学号 姓名 性别 出生日期 专业 所在系 联系电话
020101 杨颖 0 1980-7-20 计算机应用 计算机 88297147
020102 方露露 0 1981-1-15 计算机应用 计算机 88297147
020103 俞奇军 1 1980-2-20 信息管理 计算机 88297151
020104 胡国强 1 1980-11-7 信息管理 计算机 88297151
020105 薛冰 1 1980-7-29 水利工程 水利系 88297152
020201 秦盈飞 0 1981-3-10 电子商务 经济系 88297161
020202 董含静 0 1980-9-25 电子商务 经济系 88297062
020203 陈伟 1 1980-8-7 电子商务 经济系 88297171
020204 陈新江 1 1980-7-20 房建 水利系 88297171

要求:查询和“胡国强”同一个联系电话的同学的资料。。。给sql语句
要求是:创建一个视图,查询和“胡国强”同一个联系电话的同学的资料。。。给sql语句,谢谢

create view
as
select * from students where 联系电话 in
(select 联系电话 from students where name='胡国强') 这是一楼的答案,但是有点小的错误,就是查询出来的结果还有胡国强,这个是不应该的。所以这样写
create view
as
select * from students where 联系电话 in
(select 联系电话 from students where 姓名) and name<>'胡国强'

还可以使用自身连接查询。

create view
as
select S2.* from student s1,student s2
where s1.联系电话=s2.联系电话 and S1.name='胡国强' and s2.name<>'胡国强'
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-12
要求:查询和“胡国强”同一个联系电话的同学的资料。。。给sql语句

select * from students where 联系电话 in
(select 联系电话 from students where name='胡国强')

要求是:创建一个视图,查询和“胡国强”同一个联系电话的同学的资料
create view
as
select * from students where 联系电话 in
(select 联系电话 from students where name='胡国强')
第2个回答  2010-05-12
下面的那位写的很好啊!
相似回答