• SQL 语句


    casethen
    
    *********************************
    
    
    
    select * from studentStatistics
    go 
    print '成绩如何分级如下:'
    select student_name,score_Avg,
         score=case
           when score_avg between 90 and 100 then 'A'
           when score_avg between 75 and 89 then 'B'
           when score_avg between 60 and 74 then 'C'
           when score_avg<60 then 'D'
           else  '缺考'
         end
    from studentstatistics
    go
    
    
    
    *****************************
    
    go
    ************
    
    
    use master 
    go
    select * from studentinformation
    select * from studentscore
    update studentscore
    set score_test=score_test*(0.7)
    go
    
    
    
    
    
    
    ************
    
    if-else
    ***************
    
    
    declare @avgAll float
    select @avgAll=avg(score_avg)from studentstatistics
    print '平均分:'+convert(varchar(10),@avgAll)
    if(@avgAll>70) 
       begin 
           print '前三甲为:'
           select top 3 student_name,score_avg
           from studentStatistics 
           order by score_avg desc
       end
    else
       begin
           print '如下同学需要加油:'
           select  top 3 student_name,score_avg 
           from studentstatistics 
           order by score_avg
     end 
    
    
    
    
    
    ********************
    
    transaction
    ******************************
    
    
    
    begin transaction
    declare @errorCount int
    set @errorCount=0
    update bankTest
    set current_money=current_money-1000 --999
    where customer_name='A'
    set @errorCount=@errorCount+@@error
    update BankTest
    set current_money=current_money+1000
    where customer_name='B'
    set @errorCount=@errorCount+@@error
    print '账户余额:'
    select * from BankTest
    if(@errorCount!=0)
    begin
     print '转账失败,执行回滚'
    rollback transaction
    end
    else 
    begin 
    print '转账成功,执行提交'
    commit transaction
    end 
    print '账户余额:'
    select * from BankTest
    go
    
    
    
    
    *************
    
    virable1
    
    ************
    
    
    
    use testNccp
    go
    declare @age int
    set @age=
       (select student_age from studentinformation
    where student_name='成龙')
    
    select * from studentinformation
    where student_age=@age
    go
    
    
    
    
    ***********
    
    virable2
    
    *******************
    
    
    
    use testNccp
    go
    declare @name varchar(20),@age int
    set @name='成龙'
    set @age=
       (select student_age from studentinformation
    where student_name=@name)
    
    select * from studentinformation
    where student_age=@age
    go
    
    
    
    
    
    
    
    ***************
    while
    ***********************
    
    
    
    
    create table studentTest
    ( student_name varchar(20),score_java int)
    
    go 
    insert into studentTest values('haobin',57)
    
    go
    declare @scoreJava int
    while(1=1)
        begin
         select @scoreJava=(
             select score_java
             from studenttest
             where student_name='haobin'
            )
         if (@scorejava<60)
             begin
               print '加一分'
               update studentTest
               set score_java=score_java+1
               print '成绩为:'+convert(varchar(50),@scoreJava+1)
             end 
         else 
             break
      end 
    go
    

      

  • 相关阅读:
    设计模式-14-桥接模式
    设计模式-13-中介者模式
    设计模式-12-命令模式
    设计模式-11-外观模式
    设计模式-10-装饰器
    设计模式-9-模板
    设计模式-8-适配器模式-组合
    设计模式-8-适配器模式-继承
    设计模式-7-策略模式+工厂模式
    设计模式-7-策略模式
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3413058.html
Copyright © 2020-2023  润新知