一道sql面试题附答案
时间:2024-01-18 04:50:33
有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
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
asp sql去左右空格函数
Python+decimal完成精度计算的示例详解
Django框架实现的普通登录案例【使用POST方法】
![](https://img.aspxhome.com/file/2023/5/88895_0s.png)
DIV与Table布局在大型网站的可用性比较
![](https://img.aspxhome.com/file/UploadPic/200710/8/2007108125233616s.jpg)
两行代码实现的QQ窗口抖动效果
用 Python 定义 Schema 并生成 Parquet 文件详情
深入浅析Python科学计算库Scipy及安装步骤
pandas.DataFrame中提取特定类型dtype的列
Python正则表达式教程之一:基础篇
基于PyQT实现区分左键双击和单击
web项目中golang性能监控解析
详解MySQL中的数据类型和schema优化
![](https://img.aspxhome.com/file/2023/0/128020_0s.png)
Python地理地图可视化folium标记点弹窗设置代码(推荐)
![](https://img.aspxhome.com/file/2023/1/70871_0s.jpg)
关于python变量的引用以及在底层存储原理
web程序员的思考
解决MybatisPlus SqlServer OFFSET 分页问题
如何使用FSO修改文件夹的名称
条件注释使用指南[译]
python调试模式无响应解决案例
![](https://img.aspxhome.com/file/2023/0/101280_0s.jpg)
python中读入二维csv格式的表格方法详解(以元组/列表形式表示)
![](https://img.aspxhome.com/file/2023/5/65495_0s.png)