有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
您可能感興趣的文章:- 批量執行sql語句的方法
- 在SQL Server啟動時自動執行存儲過程。
- 提高SQL的執行效率的ASP的五種做法
- asp在線執行sql語句的函數
- 為什么ASP中執行動態SQL總報錯誤信息?提示語句語法錯誤
- mysql 顯示SQL語句執行時間的代碼
- php執行sql語句的寫法
- 高級MySQL數據庫面試問題 附答案
- sql面試題(查看數據中指定幾行記錄)
- 騰訊面試:一條SQL語句執行得很慢的原因有哪些?---不看后悔系列(推薦)