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

帮忙写个SQL,多谢

2012-04-06 
帮忙写个SQL,谢谢create table test(a int,b char,c char)insert into test values(1,a,b)insert into

帮忙写个SQL,谢谢
create table test(
a int,
b char,
c char
)

insert into test values(1,'a','b')

insert into test values(2,'a','b')

insert into test values(3,'b','c')

要得到如下结果(请考虑如果有多行相同的数据):
a b c
----------- ---- ----
1 a b
2 a b



[解决办法]

SQL code
;with cte as (select b,c,count(1) num from testgroup by b,c having count(1)>1)select * from test t where exists(select 1 from cte where b=t.b and c=t.c)
[解决办法]
SQL code
SELECT  A.*FROM    test A        INNER JOIN ( SELECT b ,                            c                     FROM   test                     GROUP BY b ,                            c                     HAVING COUNT(1) > 1                   ) T ON A.b = T.b                          AND A.c = T.c 

热点排行