zoukankan      html  css  js  c++  java
  • SqlServer和Oracle中一些常用的sql语句4 局部/全局变量

    --把wh1仓库号中姓名含有"平"字的职工工资在原来的基础上加288
    update 职工备份 set 工资=工资+288 where 仓库号='wh1' and 姓名 like '%平%'
    
    --把"北京"地区的职工的工资减少100,再增加1倍
    update 职工备份 set 工资=(工资-100)*2 where 仓库号 in
       (select 仓库号 from 仓库备份 where 城市='北京')
       
    --把面积小于"北京"地区最小面积的仓库面积增加80
    update 仓库备份 set 面积=面积+80 where 面积<
      ( select MIN(面积) from 仓库备份 where 城市='北京')
      
    --把工资大于不同仓库的所有平均工资的职工的工资减少66  
    update 职工备份 set 工资=工资-66 where 工资> all(
       select AVG(工资) from 职工备份 group by 仓库号)
    
    --删除面积最大和最小的仓库信息   
    delete 仓库备份 where 面积 in ( 
    (select MAX(面积) from 仓库备份),
    (select min(面积) from 仓库备份)
    )
       
    --删除工资大于所有职工平均工资的职工信息
    delete 职工备份 where 工资> (select AVG(工资) from 职工备份 )
    
    --删除"上海","济南"的所有职工信息
    delete 职工备份 where 仓库号 in
        (select 仓库号 from 仓库备份  where 城市 in('上海','济南'))
    
    --局部变量声明 赋值 输出 
    declare @str1 char(10),@str2 varchar(50), @x1 int, @x2 real,@time1 datetime
    set @str1='good'
    set @str2='hello,how are you?'
    set @x1=12
    set @x2=15
    set @time1='2009/05/06'
    print @str1
    print @str2
    print @x1
    print @x2
    print @time1
    
    --局部变量声明 赋值 输出
    declare @str1 char(10),@str2 varchar(50), @x1 int, @x2 real,@time1 datetime
    select @str1='good',@str2='hello,how are you?',@x1=12,@x2=15,@time1='2009/05/06'
    select @str1 as 字符变量1,@str2 as 字符变量2,
           @x1 as 整型变量1,@x2 as 整型变量2,@time1 as 日期时间变量
    
    --局部变量
    declare @x int
    set @x=2000
    select * from 职工 where 工资>@x
    
    --全局变量
    PRINT @@version

  • 相关阅读:
    Java多线程缓存器简单实现
    synchronized Lock用法
    【项目】01CMS的CRUD
    RabbitMQ模式,RabbitMQ和springboot整合,RabbitMQ全链路消息不丢失解决
    FreeMarker在项目中实际运用随感
    自定义异常springMVC&springCloud
    单例设计模式懒汉式和恶汉式
    浅析重不重写hashcode和equals对于HashSet添加元素的影响
    JAVA异常处理原理浅析
    Static(静态)关键字入门
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234277.html
Copyright © 2011-2022 走看看