Sql進修第三天——SQL 關於with ties引見。本站提示廣大學習愛好者:(Sql進修第三天——SQL 關於with ties引見)文章只能為提供參考,不一定能成為您想要的結果。以下是Sql進修第三天——SQL 關於with ties引見正文
關於with ties
關於with ties普通是和Top , order by相聯合應用的,會查詢出最初一條數據額定的前往值(說明:假如依照order by 參數排序TOP n(PERCENT)前往了後面n(pencent)個記載,然則n+1…n+k筆記錄和排序後的第n筆記錄的參數值(order by 前面的參數)雷同,則n+1、…、n+k也前往。n+1、…、n+k就是額定的前往值)。
試驗:
試驗用表(PeopleInfo):
CREATE TABLE [dbo].[PeopleInfo](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
[numb] [nchar](10) COLLATE Chinese_PRC_CI_AS NOT NULL,
[phone] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
向表中拔出數據:
insert into peopleinfo([name],numb,phone) values ('李歡','3223','1365255')
insert into peopleinfo([name],numb,phone) values ('李歡','322123','1')
insert into peopleinfo([name],numb,phone) values ('李名','3213112352','13152')
insert into peopleinfo([name],numb,phone) values ('李名','32132312','13342563')
檢查拔出的全體數據:
select * from dbo.PeopleInfo
成果圖:
操作步調1:不消with ties
代碼:
select top 3 * from peopleinfo order by [name] desc
成果如圖:
操作步調2:用with ties
代碼:
select top 3 with ties * from peopleinfo order by [name] desc
成果如圖:
假如with ties不與top和order by聯合應用的毛病示范:
操作步調1:不與order by聯合應用,只和top聯合應用:
代碼:
select top 3 with ties * from peopleinfo
毛病新聞如圖:
操作步調2:不與top聯合應用,只和order by聯合應用:
代碼:
select with ties * from peopleinfo order by [name] desc
毛病新聞如圖:
操作步調3:不與top聯合應用也不與order by聯合應用:
代碼:
select with ties * from peopleinfo
毛病新聞如圖: