首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

新手请问 GROUP BY 语句

2012-02-29 
新手请教 GROUP BY 语句?表名:table1abc123122112212222123结果:显示出相同的一条,例如:123不相同的不显示

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

热点排行