| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2120 人关注过本帖
标题: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
快速回复:self join求助
数据加载中...
 
   



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

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