sql查询

ghost123cc 2011-08-15 05:22:22
一张表中有id,而且这张表中id 是重复的 , 在这重复的基础上有不同的值。
写一个sql 查询出来所有id相等的并且重复值大于1的。
...全文
136 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
dllcash 2011-08-17
  • 打赏
  • 举报
回复
select * from table group by id having count(*)>1
重复大于1次的id都会出来
THG8888 2011-08-16
  • 打赏
  • 举报
回复
select * from tb group by id having count(*)>1 加分了
rucypli 2011-08-15
  • 打赏
  • 举报
回复
select id
from tb
group by id
having count(*)>1
--小F-- 2011-08-15
  • 打赏
  • 举报
回复
select
*
from
tb
where
id
in
(select id from tb group by id having count(1)>1)
吾日三省- 2011-08-15
  • 打赏
  • 举报
回复
select * from tb group by id having count(*)>1

这个了



xiaojinhua1988 2011-08-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ssp2009 的回复:]

SQL code
select * from tb group by id having count(*)>1
[/Quote]
正解
cn_gaowei 2011-08-15
  • 打赏
  • 举报
回复
#创建test表
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`ID` int(11) default '0',
`name` varchar(255) NOT NULL default 'name'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

#添加模拟数据
INSERT INTO `test` VALUES (1,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (4,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (5,'name');
INSERT INTO `test` VALUES (3,'name');
INSERT INTO `test` VALUES (2,'name');
INSERT INTO `test` VALUES (1,'name');
INSERT INTO `test` VALUES (1,'name');

#条件:查询ID重复条数>1的记录
#测试数据有十条,ID只有2和5不满足
#所以应该除了这两条记录都可以查询到
select test.* from test
inner join
(
select ID,count(*) num from test group by ID
) tmp
where test.ID = tmp.ID and tmp.num >1
MOXIE519 2011-08-15
  • 打赏
  • 举报
回复
select id from table group by id having count(id)>1
kaka2010dodo 2011-08-15
  • 打赏
  • 举报
回复

[Quote=引用 2 楼 ssp2009 的回复:]

SQL code
select * from tb group by id having count(*)>1
[/Quote]

++
wx_1021 2011-08-15
  • 打赏
  • 举报
回复

select * from tb group by id >1

凡是大于1的都是多出来重复的
gzas1989 2011-08-15
  • 打赏
  • 举报
回复
LS正解
对数据分组以后统计~
快溜 2011-08-15
  • 打赏
  • 举报
回复
select * from tb group by id having count(*)>1
chuanzhang5687 2011-08-15
  • 打赏
  • 举报
回复
没看懂

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧