比如有表
a b c
a1 b1 c1
a1 b3 c5
a2 b3 c5
a3 b5 c8我想得出下面的结果:
a b c
a1 b1 c1
a2 b3 c5
a3 b5 c8就是有的记录重复,我想选出重复的记录的第一条,不重复的就直接选出来
谢谢了
a b c
a1 b1 c1
a1 b3 c5
a2 b3 c5
a3 b5 c8我想得出下面的结果:
a b c
a1 b1 c1
a2 b3 c5
a3 b5 c8就是有的记录重复,我想选出重复的记录的第一条,不重复的就直接选出来
谢谢了
select min(id) as n,a,b,c from table group by a,b,c
select a,b,c from #t g
where not exists(select * from #t where a=g.a and id<g.id)
SELECT 'a1', 'b1', 'c1' UNION ALL
SELECT 'a1', 'b3', 'c5' UNION ALL
SELECT 'a2', 'b3', 'c5' UNION ALL
SELECT 'a3', 'b5', 'c8' SELECT A , MIN(B ) AS B,MIN( C) AS C
FROM @T
GROUP BY A
(
a varchar(5),
b varchar(5),
c varchar(5)
)insert A select 'a1','b1','c1'
insert A select 'a1','b3','c5'
insert A select 'a2','b3','c5'
insert A select 'a3','b5','c8'select a, min(B) as b,min(c) as c from A group by A