寻求一个SQL写法

xl_hao 2010-01-09 07:37:48
1:我有一个档案表,我想找出其中身份证号码相同的,取出有相同身份证号的这个身份证号;
...全文
98 10 打赏 收藏 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
daizhe 2010-01-10
  • 打赏
  • 举报
回复
hql也可以的
py330316117 2010-01-09
  • 打赏
  • 举报
回复
lz的问题就有毛病,什么叫找相同的id,再把id取出来?你都知道id了还找什么id,
"select id from Archive where id=?"
然后你只要用
PreparedStatement类中的setString方法设置id值就行了,这样就能完成你说的从表中取出id相同的id的值了,不过有必要这么做吗?

xl_hao 2010-01-09
  • 打赏
  • 举报
回复
不过俺还想多嘴问一下,这样的sql 语句,hql能写出来么?
xl_hao 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 daizhe 的回复:]
SQL codeselect IDCardfrom (select IDCard,count(IDCard)as nfrom Archivegroupby IDCard)as awhere n>1
[/Quote]

谢谢了!……
link_biao 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 daizhe 的回复:]
SQL codeselect IDCardfrom (select IDCard,count(IDCard)as nfrom Archivegroupby IDCard)as awhere n>1
[/Quote]

这个很好。
islandrabbit 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 daizhe 的回复:]
SQL codeselect IDCardfrom (select IDCard,count(IDCard)as nfrom Archivegroupby IDCard)as awhere n>1
[/Quote]

完美!
daizhe 2010-01-09
  • 打赏
  • 举报
回复

select IDCardfrom (select IDCard,count(IDCard) as n from Archive group by IDCard) as a where n>1
daizhe 2010-01-09
  • 打赏
  • 举报
回复

select id from (select id,count(id) as n from 档案表 group by id) as a where n>1
阿_布 2010-01-09
  • 打赏
  • 举报
回复

select * from Archive where IDCard='身份证号';
xl_hao 2010-01-09
  • 打赏
  • 举报
回复
设档案表名字:Archive 身份证字段为IDCard

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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