1/1页1 跳转到查看:3037
发新话题 回复该主题

排除字段重复行的SQL

排除字段重复行的SQL

--
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[test]
GO

CREATE TABLE [dbo].[test] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[score] [int] NULL
)
ON [PRIMARY]
GO
truncate table test
Insert into test(name,score)
select 'a',11 union
select 'b',22 union
select 'b',33 union
select 'c',44 union
select 'c',55
--

SELECT * FROM test

select * from test where [id] in (select [id] from
(
 
select name,id=(select min([id]) from test where [name]=test1.name) from
  (
select distinct [name] from test)test1
)test2
)
 ³p}êÀø‰€bbs.szblogs.com¬œKB$E\—

TOP

 
1/1页1 跳转到
发表新主题 回复该主题