select Mobile,mesdst from TB_Mobile 在你显示的时候处理。如何处理?跟的怎么显示有关系,
declare @TB_Mobile table (id int,Mobile int,mesdst int,other varchar(1)) insert into @TB_Mobile select 1,139139,77,'a' union all select 2,139139,77,'b' union all select 3,139139,77,'c' union all select 4,139132,77,'d' union all select 5,139132,77,'e' union all select 6,139133,77,'f' union all select 7,139134,77,'g' union all select 8,139134,77,'h'select * from @TB_Mobile a where id=(select min(id) from @TB_Mobile where Mobile=a.Mobile and mesdst=a.mesdst) order by id /* id Mobile mesdst other ----------- ----------- ----------- ----- 1 139139 77 a 4 139132 77 d 6 139133 77 f 7 139134 77 g */
create table #temp(id int,Mobile varchar(50),mesdst varchar(30)) insert into #temp select 1,'11','a' union all select 2,'11','b' union all select 3,'22','a' union all select 4,'22','b' union all select 5,'22','c' union all select 6,'33','a' union all select 7,'33','b' union allselect * from #tempselect * from #temp t where id=(select min(id) from #temp where t.Mobile=Mobile)
select * from TB_Mobile where id in ( select mind(id) from TB_Mobile group by Mobile )
declare @TB_Mobile table (id int,Mobile int,mesdst int,other varchar(1))
insert into @TB_Mobile
select 1,139139,77,'a' union all
select 2,139139,77,'b' union all
select 3,139139,77,'c' union all
select 4,139132,77,'d' union all
select 5,139132,77,'e' union all
select 6,139133,77,'f' union all
select 7,139134,77,'g' union all
select 8,139134,77,'h'select * from @TB_Mobile a
where id=(select min(id) from @TB_Mobile
where Mobile=a.Mobile and mesdst=a.mesdst)
order by id
/*
id Mobile mesdst other
----------- ----------- ----------- -----
1 139139 77 a
4 139132 77 d
6 139133 77 f
7 139134 77 g
*/
insert into #temp
select 1,'11','a' union all
select 2,'11','b' union all
select 3,'22','a' union all
select 4,'22','b' union all
select 5,'22','c' union all
select 6,'33','a' union all
select 7,'33','b' union allselect * from #tempselect * from #temp t where id=(select min(id) from #temp where t.Mobile=Mobile)
select * from TB_Mobile where id in (
select mind(id) from TB_Mobile group by Mobile
)