笔记91 查询name相同int3最小的记录,处理重复值中的方法

笔记91 查询name相同int3最小的记录,处理重复值中的方法

 1 --查询name相同int3最小的记录,处理重复值中的方法
 2 --链接:http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
 3 --查询name相同int3最小的记录,处理重复值中的方法一
 4 USE tempdb
 5 
 6 IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'#A表') AND type in (N'U'))
 7 DROP TABLE #A表
 8 
 9 CREATE TABLE  #A表
10 ([intType] int,[name] varchar(4),[int3] int)
11 insert #A表
12 select 0,'张三',2 union all
13 select 99,'张三',0 union all
14 select 0,'李四',2 union all
15 select 99,'李四',1 union all
16 select 99,'王五',1 union all
17 select 99,'赵六',0 union all
18 select 0,'赵六',0 union all
19 select 99,'X',0 union all
20 select 0,'Y',0
21 
22 
23 SELECT * FROM #A表 a WHERE int3 =(SELECT MIN(int3) FROM #A表 WHERE name=a.name )
24 
25 
26 
27 select * from #A表

 

posted @ 2013-08-02 23:16  桦仔  阅读(321)  评论(0编辑  收藏  举报