Home > Database > Mysql Tutorial > 一道sql面试题附答案

一道sql面试题附答案

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:57:26
Original
1092 people have browsed it

一道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
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template