with ties 指定从结果集中返回符合条件的额外的行数据。
场景:获取分数最大的1条数据,如果有多条相同就显示多条。
--drop table test1;
CREATE TABLE test1(
id int IDENTITY(1,1) NOT NULL,
score int NOT NULL,
usernmae nchar(10) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[test1] ADD CONSTRAINT [DF_test1_score] DEFAULT ((0)) FOR [score]
GO
INSERT INTO test1 (score,usernmae) VALUES(10,'小王'),(20,'小强'),(100,'小霞'),(100,'松松');