1. 查询雇员(employee)的姓和名
Select substring(username,1,1) as 姓 from employee
Select substring(username,2,2) as 名 from employee
2. 查询雇员的姓名
Select username from employee
3. 查询雇员数
Select count(*) from employee
4. 查询雇员的姓名和职务
Select username,,duty from employee
5. 查询雇员的工龄
Select year(getdate())-开始工作日期 as 工龄 from employee
任务2:条件查询
1. 查询雇员(employee)从事"Sales Representative"职务的有哪些人
Select * from employee where duty=’ Sales Representative’
2. 查询工龄超过15年的雇员
Select * from employee where cast( (year(getdate())-开始工作日期) as int)>=15
3. 查询姓以a开头的雇员
Select * from employee where username like ‘a%’
4. 查询姓的开头字母在m以后的雇员
Select * from employee where cast((substring(username,1,1) as varchar)>=’m’
5. 认为hire_date是雇员生日,查询巨蟹座的雇员
Select * from employee where birthday between ‘6-22 ‘ and ‘7-22’
任务3:联合查询
1. 查询雇员和雇员职位
Select a.id,b.duty from employee, as a,jobs as b
2. 查询雇员、雇员职位和雇员所在出版社
Select a.id,b.duty, b.publishing from employee as a,jobs as b on a.id=b.id
3. 查询雇员、雇员工资、雇员离本职位最高工资的差值
select a. ID,a.username,a.[雇员工资],b.[最高工资]-a.[雇员工资] as [差值] from employee a,jobs b where a.[职位]=b.[职位]
nani 你的教科书上都有的 亲爱的
都是最基本的,直接写就好了。
查询雇员(employee)的姓和名
Select substring(username,1,1) as 姓 from employee
Select substring(username,2,2) as 名 from employee