SQL WITH TIES

http://msdn.microsoft.com/zh-cn/library/ms189463(v=sql.110).aspx

指定查询结果集包含与返回的最后一行中一个或多个 ORDER BY 列中的值匹配的任何其他行。 这可能导致返回的行数多于在 expression 中指定的值。 例如,如果 expression 设置为 5,而 2 个其他行与第 5 行中 ORDER BY 列的值匹配,则结果集将包含 7 行。

只能在 SELECT 语句中且只有在指定了 ORDER BY 子句之后,才能指定 TOP...WITH TIES。 返回的记录关联顺序是任意的。 ORDER BY 不影响此规则。

CREATE TABLE students(
	id int IDENTITY(1,1) NOT NULL,
	score int NULL
) ON PRIMARY
GO
INSERT INTO students (score) VALUES (100)
INSERT INTO students (score) VALUES (100)
INSERT INTO students (score) VALUES (100)
INSERT INTO students (score) VALUES (90)
INSERT INTO students (score) VALUES (90)
INSERT INTO students (score) VALUES (85)
INSERT INTO students (score) VALUES (84)
INSERT INTO students (score) VALUES (80)
INSERT INTO students (score) VALUES (80)
INSERT INTO students (score) VALUES (75)
INSERT INTO students (score) VALUES (74)
INSERT INTO students (score) VALUES (70)
SELECT TOP 8 * FROM students ORDER BY score DESC


SELECT TOP 8 WITH TIES * FROM students ORDER BY score DESC


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值