oracle查询小结
2016-04-26 14:41
591 查看
一、查询某表中某列值相同的记录:
select * from t_acct_map where acct_id in (
select acct_id from t_acct_map group by acct_id having count(*)>1
)
order by acct_id
二、自连接
当表中的某一个字段与这个表中另外字段的相关时,才可能用到
select bi.brh_nm||'_'||bi.brh_id||'_'||bi.sup_brh_id sub,' 的父公司 ',b.brh_nm||b.brh_id sup
from t_brh_info b ,t_brh_info bi
where b.brh_id=bi.sup_brh_id
union select brh_nm||'_'||brh_id sub,' 的父公司 ', brh_nm||'_'||sup_brh_id sup from t_brh_info where sup_brh_id is NULL
order by sup desc
;
select * from t_acct_map where acct_id in (
select acct_id from t_acct_map group by acct_id having count(*)>1
)
order by acct_id
二、自连接
当表中的某一个字段与这个表中另外字段的相关时,才可能用到
select bi.brh_nm||'_'||bi.brh_id||'_'||bi.sup_brh_id sub,' 的父公司 ',b.brh_nm||b.brh_id sup
from t_brh_info b ,t_brh_info bi
where b.brh_id=bi.sup_brh_id
union select brh_nm||'_'||brh_id sub,' 的父公司 ', brh_nm||'_'||sup_brh_id sup from t_brh_info where sup_brh_id is NULL
order by sup desc
;
相关文章推荐
- Duplication with Oracle Managed Files(OMF)
- Oracle 排序中使用nulls first 或者nulls last 语法
- Oracle-BPM(十)
- oracle字符集的问题
- ORACLE數據庫慢排除
- iptables的nf_conntrack相关参数引起两个问
- Oracle 表分区与索引分区
- _use_adaptive_log_file_sync参数分析
- Oracle 控制文件和日志文件
- 《oracle每天一练》触发器不能调用或间接调用COMMIT,ROLLBACK等DCL语句
- oracle 分组编号 ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN ) 的用法
- Oracle default 函数记录(sys_guid......)
- Oracle EBS中订单登记后,发放销售订单以便挑库时,找不到相应的销售订单
- oracle 删除步骤
- Oracle中的分组group by rollup/cube
- oracle启动过程
- Oracle中tnsping命令解析
- Oracle正则表达式使用介绍
- Oracle编译存储过程卡死的问题
- oraclelinux系统udev配置