一些sql

--关联更新
update t_stf_duty_info  t set dept_id =(select dept_id from t_stf_base where t.employee_id=employee_code);
--查询重复记录
select employee_code from t_stf_base group by employee_code having count(*)>1;--重复记录
--大小写转换
UPDATE 表 SET 字段 = upper(字段), 字段 = LOWER(字段)  


---查询一个人两条最新记录
 select * from (
   select count(1) as num,employee_id from T_STF_POSITION where is_last_='1' group by employee_id)
   where num=2;
   
---年龄字段的更新
 update t_stf_base set age_=(to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy'))
 
--日期更新
update  表名  set   日期 = to_date('','yyyymmdd') where ..............
update t_stf_base  t set birthday =(select birthday from TEXT_BIRTHDAY where t.employee_id=employee_id);


--分组前面列几个字段,group by 后面也要列几个字段
select t.name,t.dept_id,t.sex from t_stf_base t group by t.name,t.dept_id,t.sex having count(name)>1


-------------获得当前年月日
select to_char(SYSDATE, 'YYYY') || '年' || to_char(SYSDATE, 'MM') || '月' ||
       to_char(SYSDATE, 'DD') || '日' as currentDate
  from t_stf_base --当前日期
  
例如:
select t.employee_id,t.name,t.sex,t.id_code,t.employee_code,a.BEGIN_DATE_,a.END_DATE_,
to_char(SYSDATE, 'YYYY') || '年' || to_char(SYSDATE, 'MM') || '月' ||
       to_char(SYSDATE, 'DD') || '日' as currentDate
from t_stf_base t
left join T_STF_CONTRACT_INFO a 
on t.employee_id=a.employee_id_
where t.employee_id='6900'  
  
---------------------------------------------------------
学习经历最新字段赋值:
--第一步
update t_stf_edu_exp set HIGHEST_EDU=''
update t_stf_edu_exp set HIGHEST_DEGREE=''
--第二步
 update t_stf_edu_exp
      set highest_edu = 1
    where edu_id in (select edu_id
                       from (select *
                               from (select t_stf_edu_exp.*,
                                            row_number() over(partition by employee_Id order by END_DATE DESC) cn
                                       from t_stf_edu_exp where end_date is not null)
                              where cn = 1))
--第三步
update t_stf_edu_exp set HIGHEST_EDU='0' where HIGHEST_EDU is null
update t_stf_edu_exp set HIGHEST_DEGREE=HIGHEST_EDU
------------------------------------------
职称新增最新字段赋值
 update T_STF_TECHNIC_INFO
      set is_last = 1
    where num_id in (select num_id
                       from (select *
                               from (select T_STF_TECHNIC_INFO.*,
                                            row_number() over(partition by employee_Id order by ASSESS_DATE DESC) cn
                                       from T_STF_TECHNIC_INFO)
                              where cn = 1))


---------------------------------------------
行政职务最新字段赋值
 update t_Stf_Duty
      set duty_status = 1
    where id in (select id
                       from (select *
                               from (select t_Stf_Duty.*,
                                            row_number() over(partition by employee_Id order by START_DATE DESC) cn
                                       from t_Stf_Duty)

                              where cn = 1))

-------------------------------------------------------

oracle根据出生日期算年龄:
select floor(months_between(to_date(concat(extract(year from sysdate),'-10-31'),'YYYY-MM-DD'),to_date(生日的日期,'yyyy-mm-dd'))/12)  from table_name


floor 向下取整
months_between 日期相差的月份数
concat字字符串连接
extract(year from sysdate) 返回当前日期的年份




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值