本文介紹了SQL 查詢中 SELECT 語句中 WITH TIES 關(guān)鍵字的用途是什么?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
SELECT TOP 5 WITH TIES EmpNumber,EmpName
FROM Employee
Order By EmpNumber DESC
以上查詢返回超過五個(gè)結(jié)果,With Ties"關(guān)鍵字SQL查詢有什么用處.
This above query return more than five result, What is the use of "With Ties" keyword SQL Queries.
推薦答案
來自 TOP (Transact-SQL)
當(dāng)你想返回與最后一個(gè)位置并列的兩行或更多行時(shí)使用在有限的結(jié)果集中.
Used when you want to return two or more rows that tie for last place in the limited results set.
注意例子
我們有一張桌子,有 6 個(gè)整數(shù),1 到 4 和 5 兩次.
We have a table with 6 entires 1 to 4 and 5 twice.
運(yùn)行
SELECT TOP 5 WITH TIES *
FROM MyTable
ORDER BY ID;
返回 6 行,因?yàn)樽詈笠恍惺遣⒘械?存在多次.)
returns 6 rows, as the last row is tied (exists more than once.)
在哪里
SELECT TOP 5 WITH TIES *
FROM MyTable
ORDER BY ID DESC;
只返回 5 行,因?yàn)樽詈笠恍?在本例中為 2)只存在一次.
returns only 5 rows, as the last row (2 in this case) exists only once.
這篇關(guān)于SQL 查詢中 SELECT 語句中 WITH TIES 關(guān)鍵字的用途是什么?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!