看CSDN测试后,关于领导职工显示的问题!!!
来源:互联网 发布:淘宝活性炭都是假的吗 编辑:程序博客网 时间:2024/05/01 01:21
create table staff(staff_id int,staff_name varchar(6))---建测试表,职工表
go
insert staff
select 1,'小王' union all
select 2,'小刘' union all
select 3,'赵科长'union all
select 4,'吴经理' union all
select 5, '董主任'
go
select * ---------------显示表记录
from staff
go
create table staff_leader_relation(staff_id int ,leader_id int )----建立员工关系表
alter table staff_leader_relation add constraint pk_relation foreign key(staff_id) references staff(staff_id) -----表外建FK
go
alter table staff add constraint pk primary key nonclustered(staff_id)---------------- PK
alter table staff_leader_relation add constraint pk2_relation foreign key(leader_id) references staff(staff_id)
go
select *
from staff_leader_relation --- 此时为空,可先为两个有外键联系的表先建立外键约束,再输入记录
go
insert staff_leader_relation
select 1,3 union all
select 2,3 union all
select 3,4 union all
select 5,4
go
select *
from staff_leader_relation
----展现出-----------------------------------------------------------------
staff_name leader_name
----------------------------------------------------------------------------------
select x.staff_name,y.staff_name as leader_name ---------我作的,可显示,但是没有作业领导职工的人显示不出来
from staff x,staff_leader_relation s,staff y
where x.staff_id=s.staff_id and s.leader_id=y.staff_id
select distinct a.staff_name,c.staff_name as leader_name from staff a,staff_leader_relation b,staff c -------- 同上
where a.staff_id=b.staff_id
and b.leader_id=c.staff_id
order by a.staff_name
select ---------------splory给出的完整答案,包括职工吴经理(null)
(select staff_name from staff where staff_id=a.staff_id) xiashu
,(select staff_name from staff where staff_id=b.leader_id) lingdao
from staff a left join sl_ralation b
on a.staff_id=b.staff_id
---------------------------------------------
--------------------------------------------
select A.staff_name,B.staff_name -----------中山大学开出答案
from staff A,staff B,sl_ralation C
where A.staff_id=C.staff_id and B.staff_id=C.leader_id
union
select A.staff_name,null
from staff A
where A.staff_id not in (select staff_id from sl_ralation)
go
insert staff
select 1,'小王' union all
select 2,'小刘' union all
select 3,'赵科长'union all
select 4,'吴经理' union all
select 5, '董主任'
go
select * ---------------显示表记录
from staff
go
create table staff_leader_relation(staff_id int ,leader_id int )----建立员工关系表
alter table staff_leader_relation add constraint pk_relation foreign key(staff_id) references staff(staff_id) -----表外建FK
go
alter table staff add constraint pk primary key nonclustered(staff_id)---------------- PK
alter table staff_leader_relation add constraint pk2_relation foreign key(leader_id) references staff(staff_id)
go
select *
from staff_leader_relation --- 此时为空,可先为两个有外键联系的表先建立外键约束,再输入记录
go
insert staff_leader_relation
select 1,3 union all
select 2,3 union all
select 3,4 union all
select 5,4
go
select *
from staff_leader_relation
----展现出-----------------------------------------------------------------
staff_name leader_name
----------------------------------------------------------------------------------
select x.staff_name,y.staff_name as leader_name ---------我作的,可显示,但是没有作业领导职工的人显示不出来
from staff x,staff_leader_relation s,staff y
where x.staff_id=s.staff_id and s.leader_id=y.staff_id
select distinct a.staff_name,c.staff_name as leader_name from staff a,staff_leader_relation b,staff c -------- 同上
where a.staff_id=b.staff_id
and b.leader_id=c.staff_id
order by a.staff_name
select ---------------splory给出的完整答案,包括职工吴经理(null)
(select staff_name from staff where staff_id=a.staff_id) xiashu
,(select staff_name from staff where staff_id=b.leader_id) lingdao
from staff a left join sl_ralation b
on a.staff_id=b.staff_id
---------------------------------------------
--------------------------------------------
select A.staff_name,B.staff_name -----------中山大学开出答案
from staff A,staff B,sl_ralation C
where A.staff_id=C.staff_id and B.staff_id=C.leader_id
union
select A.staff_name,null
from staff A
where A.staff_id not in (select staff_id from sl_ralation)
- 看CSDN测试后,关于领导职工显示的问题!!!
- 关于领导的思考
- 关于新浪微博秀添加后的测试问题
- 感谢CSDN领导的帮助
- 关于EF4.1更新数据后的显示问题-----PagedList
- 关于android语言切换后通知栏显示的问题
- 关于android语言切换后通知栏显示的问题
- 关于调用history.back()后显示网页过期的问题
- 国务院关于职工探亲待遇的规定
- 关于职工全年月平均工作时间和工资折算问题的通知
- ios开发职工常常遇到的问题
- 从古代名著看领导与被领导的艺术
- 领导力的简单测试
- 知己知彼 看CIO如何成功领导80后
- 测试一下csdn的代码显示功能
- 从易经看领导力的培养
- 关于poi/Npoi创建批注后,EXCEL不能显示,wps能显示的问题
- 关于领导意图的理解
- 【原创】搞了个NetGear的路由器,为此写了个小程序来查Wan IP.
- 关于子类对象的实例化过程
- 比尔·盖茨--美国肥沃的创业土壤里长出的大树
- Subversion for Windows 安装指南
- 由EOF和NULL引起的一个C程序的分析
- 看CSDN测试后,关于领导职工显示的问题!!!
- 一个让98%的JAVA程序员犯难的程序
- 欢迎
- 《深度探索C++对象模型》读书笔记(1)
- Dive Into Python学习日志
- lljs的J@Whiz1.4笔记
- 华为交换、路由器常见命令
- 世界是平的 企业要实时
- 藏在UIManager中的猫腻(转)