读书人

新手请问 GROUP BY 语句

发布时间: 2012-02-29 16:44:10 作者: rapoo

新手请教 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

读书人网 >SQL Server

热点推荐