我是郭大侠

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

--
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
)

或者

select * from test where [id] in(select min([id]) from test group by name)

 


posted on 2007-11-30 11:13  郭大侠  阅读(1030)  评论(2编辑  收藏  举报

青花帽筒

青花帽筒

龙凤罐

龙凤罐

紫檀笔筒

小罐