`
zeyuphoenix
  • 浏览: 55996 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

SQL面试题(九)

阅读更多

问题:

表如下:

------------------------------------------------------------

*

1

2

3

5

5

7

7

8

9

只显示,55,77出来,不显示别的。(注:不只是 5 7 只要重复的都要 输出)

 

建表:

create table doubleprint (id integer not null);
insert into doubleprint values (1) ,(2),(3), (4),(5),(4),(1),(7), (9),(4),(3),(11);

 

 

解答Sql:

select id from doubleprint  where (select count(id) from doubleprint a where doubleprint.id = a.id) > 1 ;

 

结果:

+------+

| id   |

+------+

|    3 |

|    4 |

|    1 |

|    4 |

|    4 |

|    3 |

|    1 |

|    1 |

+------+

 

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics