日期:2014-05-18  浏览次数:20515 次

简单问题,马上散分,显示重复行
ID         Title             num
1             aa                   1
2             bb                   3
3             cc                   4
4             dd                   3
5             ee                   4
6             ff                   1


我想实现查找后显示num唯一id和title,求助

------解决方案--------------------
select a.* from tb a,
(select num,min(id) as id from tb group by num) b
where a.num = b.num and a.id = b.id
------解决方案--------------------
create table T(ID int, Title varchar(10), num int)
insert T select 1, 'aa ', 1
union all select 2, 'bb ', 3
union all select 3, 'cc ', 4
union all select 4, 'dd ', 3
union all select 5, 'ee ', 4
union all select 6, 'ff ', 1

select * from T as tmp
where not exists(select 1 from T where num=tmp.num and ID> tmp.ID)

--result
ID Title num
----------- ---------- -----------
4 dd 3
5 ee 4
6 ff 1

(3 row(s) affected)