手边星辰

博客园 首页 新随笔 联系 订阅 管理

一、查询某表中某列值相同的记录:

  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
;

posted on 2016-04-26 14:41  手边星辰  阅读(169)  评论(0编辑  收藏  举报