标题:self join求助
只看楼主
SQL学习
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-1-20
 问题点数:0 回复次数:0 
self join求助
上星期刚开始学SQL,请教这个作业里不同于information services其它部门的BaseRate数据应该怎么写?

--use [AdventureWorksDW2012] [dbo].[DimEmployee]
--show list of Employees in other Department that have the same baseRate AS Employees in Information Services department
--only show records with baseRatee >30

--list Employee's DepartmentName,EmployeeKey,baseRate,FirstName,LastName, AND the DepartmentName,EmployeeKey,baseRate,FirstName,LastName of same base rate Employees who are
--in  Information Services department ,it is to compare Side-by-Side

程序代码:
use [AdventureWorksDW2012]
go
select distinct D1.DepartmentName AS 'Employee''s DepartmentName',D1.EmployeeKey,D1.BaseRate,D1.FirstName,D1.LastName
from [dbo].[DimEmployee]D1,[dbo].[DimEmployee]D2
where D1.[ParentEmployeeKey]=D2.[EmployeeKey] and D1.BaseRate>30 
and d1.DepartmentName <>'Information Services'
order by 3

select distinct D1.DepartmentName AS 'Employee''s DepartmentName',D1.EmployeeKey,D1.BaseRate,D1.FirstName,D1.LastName
from [dbo].[DimEmployee]D1,[dbo].[DimEmployee]D2
where D1.[ParentEmployeeKey]=D2.[EmployeeKey] and D1.BaseRate>30 
and d1.DepartmentName = 'Information Services'
order by 3
搜索更多相关主题的帖子: services records 
2016-01-20 04:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-461217-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.600930 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved