有1張表, 
Wages 表 
------------------------------------------- 
Emp_id       | 基本工資| 工齡工資| 
------------------------------------------- 
1                | 1.00        | 1.00       | 
------------------------------------------- 
2                | 1.00        | 2.00       | 
------------------------------------------- 
3                | 1.00        | 3.00       | 
------------------------------------------- 
4                | 1.00        | 4.00       | 
------------------------------------------- 
......... 
請從上表用 “一句組合查詢” 查詢出工資統(tǒng)計表,要求檢索出的內(nèi)容格式如下: 
----------------------------------------------------------------- 
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