求一条关于查身份证的SQL语句

faa171544 2009-09-18 09:07:05
表字段有id name cardid。查询出同一身份证号码有两条以上记录的身份证号码及其个数。
谢谢各位大虾先~!
...全文
418 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiangyu800 2009-09-24
  • 打赏
  • 举报
回复
SELECT cardid,COUNT(1) FROM tablename GROUP BY cardid HAVING COUNT(1) > 1

up
ruild88 2009-09-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhaoxiaoming1999 的回复:]
select count(*),cartid from abc group by cartid having count(*)>2;
[/Quote]
这个sql在数据量大的情况不够优化,较消耗资源
taksunm 2009-09-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liusong_china 的回复:]
SQL codeSELECT cardid,COUNT(1)FROM tablenameGROUPBY cardidHAVINGCOUNT(1)>1;应该是2条及两条以上吧
[/Quote]
up
duqiangcise 2009-09-18
  • 打赏
  • 举报
回复
1楼正解!
liusong_china 2009-09-18
  • 打赏
  • 举报
回复
SELECT cardid,COUNT(1) FROM tablename GROUP BY cardid HAVING COUNT(1) > 1;
应该是2条及两条以上吧
oraclemch 2009-09-18
  • 打赏
  • 举报
回复
[Quote=引用楼主 faa171544 的回复:]
表字段有id name cardid。查询出同一身份证号码有两条以上记录的身份证号码及其个数。
  谢谢各位大虾先~!

[/Quote]

select cartid,count(cartid) from tb group by cartid having count(cartid)>2
FuYongHao 2009-09-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhaoxiaoming1999 的回复:]
select count(*),cartid from abc group by cartid having count(*)>2;
[/Quote]

UP
cosio 2009-09-18
  • 打赏
  • 举报
回复
with temp as
(
select 1 a,2 b,3 c from dual
union all
select 1,2,3 from dual
union all
select 1,3,3 from dual
union all
select 1,3,3 from dual
union all
select 1,3,3 from dual
union all
select 1,5,3 from dual
union all
select 1,6,3 from dual
union all
select 1,7,3 from dual

)
select a,b,c,rn from
(
select a,b,c,count(1) rn from temp a group by a ,b,c having count(1)>1
) b
group by a,b,c
zhaoxiaoming1999 2009-09-18
  • 打赏
  • 举报
回复
select count(*),cartid from abc group by cartid having count(*)>2;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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