注册 登录
编程论坛 SQL Server论坛

练习语句

晓C→潇潇 发布于 2007-01-18 22:47, 606 次点击
例题一:
在SQL Server 数据库系统中,Northwind 数据库中的employees数据表包含了许多字段,用来记录公司内的雇员信息.其中有下面4个字段:employeesid编号标识了每个员工,Lastname和Firstname记录了该员工的全名,ReportsTo标识了该员工上级的编号.现在如何知道Fuller有多少个下属?
例题二:
在SQL Server 数据库系统中,Northwind 数据库中的employees数据表包含了许多字段,用来记录公司内的雇员信息.其中有下面4个字段:employeesid编号标识了每个员工,Lastname和Firstname记录了该员工的全名,ReportsTo标识了该员工上级的编号.现在Fuller的原下属Callahan成为Buchanan的下属,如何使用SQL语句体现这个变化?
例题三:
在SQL Server 数据库系统中,Northwind 数据库中的employees数据表包含了许多字段,用来记录公司内的雇员信息.其中有下面4个字段:employeesid编号标识了每个员工,Lastname和Firstname记录了该员工的全名,ReportsTo标识了该员工上级的编号.如何使用SQL语句列出每个员工及其下级的全名?
1 回复
#2
Kendy1234562007-01-19 11:30
1. Select Count(*) from employee where reportsto in (select employeesid from employee where firstname = 'Fuller')

2. Update employee set reportsto = (select top 1 employeesid from employee wheren firstname = 'Buchanan' ) where firstname = 'Callahan'

3. Select FullName = a.firstname+' '+a.lastname,FollowerName = b.firstname+ ' '+b.lastname from employee a
join employee b on a.employeesid = b.reportsto
1