一道sql面试题附答案
更新时间:2008年05月10日 21:40:05 作者:
一道sql面试答案
有1张表,
Wages 表
-------------------------------------------
Emp_id | 基本工资| 工龄工资|
-------------------------------------------
1 | 1.00 | 1.00 |
-------------------------------------------
2 | 1.00 | 2.00 |
-------------------------------------------
3 | 1.00 | 3.00 |
-------------------------------------------
4 | 1.00 | 4.00 |
-------------------------------------------
.........
请从上表用 “一句组合查询” 查询出工资统计表,要求检索出的内容格式如下:
-----------------------------------------------------------------
Emp_id | 基本工资| 工龄工资 | 合计 | 名次
------------------------------------------------------------------
1 | 1.00 | 1.00 |2.00 | x
------------------------------------------------------------------
2 | 1.00 | 2.00 |3.00 | y
------------------------------------------------------------------
3 | 1.00 | 3.00 |4.00 | ..
------------------------------------------------------------------
4 | 1.00 | 4.00 |5.00 | ..
------------------------------------------------------------------
回答:
begin tran
create table Wages(Emp_id bigint not null primary key,基本工资 money, 工龄工资 money)
go
insert into Wages(Emp_id,基本工资,工龄工资)values(1,1.00,1.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(2,1.00,2.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(3,1.00,3.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(4,1.00,4.00)
if @@error>0 rollback else commit tran
select Emp_id,基本工资,工龄工资,基本工资+工龄工资 as 合计,row_number() over(order by 基本工资+工龄工资) as 名次 from Wages order by 合计
--drop table Wages
Wages 表
-------------------------------------------
Emp_id | 基本工资| 工龄工资|
-------------------------------------------
1 | 1.00 | 1.00 |
-------------------------------------------
2 | 1.00 | 2.00 |
-------------------------------------------
3 | 1.00 | 3.00 |
-------------------------------------------
4 | 1.00 | 4.00 |
-------------------------------------------
.........
请从上表用 “一句组合查询” 查询出工资统计表,要求检索出的内容格式如下:
-----------------------------------------------------------------
Emp_id | 基本工资| 工龄工资 | 合计 | 名次
------------------------------------------------------------------
1 | 1.00 | 1.00 |2.00 | x
------------------------------------------------------------------
2 | 1.00 | 2.00 |3.00 | y
------------------------------------------------------------------
3 | 1.00 | 3.00 |4.00 | ..
------------------------------------------------------------------
4 | 1.00 | 4.00 |5.00 | ..
------------------------------------------------------------------
回答:
复制代码 代码如下:
begin tran
create table Wages(Emp_id bigint not null primary key,基本工资 money, 工龄工资 money)
go
insert into Wages(Emp_id,基本工资,工龄工资)values(1,1.00,1.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(2,1.00,2.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(3,1.00,3.00)
insert into Wages(Emp_id,基本工资,工龄工资)values(4,1.00,4.00)
if @@error>0 rollback else commit tran
select Emp_id,基本工资,工龄工资,基本工资+工龄工资 as 合计,row_number() over(order by 基本工资+工龄工资) as 名次 from Wages order by 合计
--drop table Wages
相关文章
CPU 核心数超过 Enterprise Server/CAL 限制问题的解决方法
最近有客户要求安装sql server 2019 数据库,安装过程中提示Enterprise Server/CAL CPU 核心利用率限制规则生成了警告,CPU 核心数超过 Enterprise Server/CAL 限制,20 个物理核心,或已启用超线程的 40 个逻辑核心,原来企业版也是有区别的2024-04-04
SQL Server的通用分页存储过程 未使用游标,速度更快!
使用SQL Server时,分页处理一直是个比较棘手的问题2010-11-11
SQL Server中的数据类型Text与varchar(max)有什么区别?
在SQL Server中,处理文本数据时,我们经常会遇到两种数据类型:Text和varchar(max),尽管它们都可以用来存储大量的文本数据,如果可能的话,考虑将Text数据类型迁移到varchar(max)或nvarchar(max)数据类型,以利用新功能和潜在的性能优势2025-03-03
通过Windows批处理命令执行SQL Server数据库备份
这篇文章主要介绍了通过Windows批处理命令执行SQL Server数据库备份的相关资料,需要的朋友可以参考下2016-03-03


最新评论