易截截图软件、单文件、免安装、纯绿色、仅160KB

请教一条快速准确的oracle查询语句

在一张表a中,有字段xm,sfzhm,rid,xb,mz等6个字段,如果xm和sfzhm相同,那么就说这两条记录相同,请教怎么将这种情况下的数据查询出来。
SQL code:

select t.* from a t where exists(select 1 from
(select xm,sfzhm from a group by xm, sfzhm having count(1) >= 2) m
where m.xm = t.xm and m.sfzhm = t.sfzhm)
order by t.xm , t.sfzhm



只有一条记录吧? 咋跑出两条记录来了?

这个可以用自连接吧

select *
from table_name a,table_name b
where a.xm = b.sfzhm

引用
SQL codeselect t.*from a twhereexists(select1from
(select xm,sfzhmfrom agroupby xm, sfzhmhavingcount(1)>=2) mwhere m.xm= t.xmand m.sfzhm= t.sfzhm)orderby t.xm , t.sfzhm


谢谢2楼,我要的就是这种结果,由于我刚学oracle,因此还请解释下这条语句,
select 1 from
(select xm,sfzhm from a group by xm, sfzhm having count(1) >= 2) m
where m.xm = t.xm and m.sfzhm = t.sfzhm,这条语句有点复杂,请解释下,谢谢。
另外能否使查询速度更快点?

引用
SQL codeselect t.*from a twhereexists(select1from
(select xm,sfzhmfrom agroupby xm, sfzhmhavingcount(1)>=2) mwhere m.xm= t.xmand m.sfzhm= t.sfzhm)orderby t.xm , t.sfzhm


select1from
(select xm,sfzhmfrom agroupby xm, sfzhmhavingcount(1)>=2) mwhere m.xm= t.xmand m.sfzh


相关问答:

oracle 10g web登陆EM的问题? - Oracle / 基础和管理

安装了Oracle 10g,默认安装了orcl数据库,这个数据库能不能删除啊,还有我如果新建了其他数据库,怎么知道在web中登陆不同数据库的地址啊?

1
可以删除
2
在WEB地址栏中输入地址的时候指定新创建的数据库的IP ......

Oracle 数据导出问题 - Oracle / 高级技术

exp user/password@dbname file=c:\table.dmp tables=jbitaku,jbitakum grants=y
然後按回車鍵 說明:  user/password@dbname  分別表示用戶名,密碼和服務名 f ......

Oracle的blob字段问题 - Oracle / 开发

查了一天的blob,还是没理解到,我想在VC下存取二进制的文件,使用的是oo4o,照着帮助文档上面的写了写入数据库的代码,还是没写对,错误提示是this operation is not permitted on a empty LOB,这是什么意思啊?照 ......

oracle 执行顺序 - Oracle / 基础和管理

SQL code:

declare
v_deptno number(2);
v_dname varchar2(14);
begin
dbms_output.put_line('请输入部门号和部门名:');
v_deptno:=&deptno;
v_dname:='&dname';
insert into dept01(deptno,dnam ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号