一道sql面試題附答案
發(fā)布日期:2022-02-03 11:38 | 文章來源:腳本之家
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|..
------------------------------------------------------------------ 回答:
begintran
createtableWages(Emp_idbigintnotnullprimarykey,基本工資money,工齡工資money)
go
insertintoWages(Emp_id,基本工資,工齡工資)values(1,1.00,1.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(2,1.00,2.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(3,1.00,3.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(4,1.00,4.00)
if@@error>0rollbackelsecommittran
selectEmp_id,基本工資,工齡工資,基本工資+工齡工資as合計,row_number()over(orderby基本工資+工齡工資)as名次fromWagesorderby合計
--droptableWages
-------------------------------------------
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|..
------------------------------------------------------------------ 回答:
復(fù)制代碼 代碼如下:
begintran
createtableWages(Emp_idbigintnotnullprimarykey,基本工資money,工齡工資money)
go
insertintoWages(Emp_id,基本工資,工齡工資)values(1,1.00,1.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(2,1.00,2.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(3,1.00,3.00)
insertintoWages(Emp_id,基本工資,工齡工資)values(4,1.00,4.00)
if@@error>0rollbackelsecommittran
selectEmp_id,基本工資,工齡工資,基本工資+工齡工資as合計,row_number()over(orderby基本工資+工齡工資)as名次fromWagesorderby合計
--droptableWages
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章