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

新手请教 GROUP BY 语句?
表名:   table1

a         b         c
1         2         3
1         2         2
1         1         2
2         1         2
2         2         2
1         2         3


结果:     显示出相同的一条,例如:   1       2       3     不相同的不显示

------解决方案--------------------
少了个条件 having count(*) > 1
------解决方案--------------------
select distinct * from table1 a where exists(select 1 from table1 where a=a.a and b=a.b and c=a.c)
------解决方案--------------------
create table table1(a int,b int ,c int)
insert table1
select 1, 2, 3
union all
select 1, 2, 2
union all
select 1, 1, 2
union all
select 2, 1, 2
union all
select 2, 2, 2
union all
select 1, 2, 3


select distinct * from table1 t where 1 <(select count(1) from table1 where t.a=a and t.b = b and t.c=c)
------解决方案--------------------
select a,b,c
from table1 t
where 1 <(select count(1) from table1 where t.a=a and t.b = b and t.c=c)
group by a,b,c
------解决方案--------------------
--try


select * from T
where a <> b and a <> c and b <> c