您的位置:首页 > 数据库 > Oracle

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
;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: