数据库-6-24

#主键值的调换(第二种:PostgreSQL和MySQL不能使用,但是Oracle,DB2,SQL Server可以使用)
#第一种
update stu_family set stu_id=99999 where stu_id=1
update stu_family set stu_id=1 where stu_id=2
update stu_family set stu_id=2 where stu_id=99999
#第二种
update stu_family set stu_id=case 
    when stu_id=1 then 2
    when stu_id=2 then 1
    else  stu_id end
    where stu_id in (1,2)

#更改信息:stu_subsidies按金额进行调节(没有使用where因为where会重叠判断,容易出现错误)
update stu_family set stu_subsidies=case
    when stu_subsidies<3000 then stu_subsidies*1.3
    when stu_subsidies<7000 then stu_subsidies*1.2
    when stu_subsidies<9000 then stu_subsidies*1.1
    else stu_subsidies end;    

#更改信息:根据stu_peoples更改stu_subsidies
update stu_family set stu_subsidies=case 
    when stu_peoples>=1 and stu_peoples<=2 then 8000
    when stu_peoples>=3 and stu_peoples<=4 then 2000
    when stu_peoples>=5 then 6000
    else 0 end;
    

#添加字段: stu_subsidies(int)
alter table stu_family add stu_subsidies int 

猜你喜欢

转载自blog.csdn.net/China_C_boss/article/details/93473370