zoukankan      html  css  js  c++  java
  • 小小SQLServer,你懂的

    declare @i int
    declare @sum int
    
    set @i=1
    set @sum=0
    
    while @i<=100
    begin
        set @sum=@sum+@i
        set @i=@i+1
    end
    
    print @sum
    
    
    if 1=10
        print ''
    else if 2=2
        print '对错'
    else 
        print ''
    
    
    
    declare @today int
    declare @week nvarchar(3)
    
    set @today=25
    set @week= 
        case 
        when @today=1 then '星期一'
        when @today=2 then '星期二'
        when @today=3 then '星期三'
        else '错误'
        end
    print @week
    
    
    create table t_a(
    id int not null,
    name varchar(5)
    )
    
    
    insert into t_a values(1,'a1')
    insert into t_a values(1,'a2')
    insert into t_a values(2,'a3')
    insert into t_a values(4,'a4')
    insert into t_a values(5,'a5')
    
    create table t_b(
    id int not null,
    name varchar(5)
    )
    
    
    insert into t_b values(1,'b1')
    insert into t_b values(1,'b2')
    insert into t_b values(2,'b3')
    insert into t_b values(4,'b4')
    insert into t_b values(5,'b5')
    
    
    select * from t_a
    union all 
    select * from t_b
    
    update t_b set name ='b3' where name='a3'
    
    
    select * from t_a left join t_b on (t_a.id=t_b.id)
    
    select * from t_a right join t_b on(t_a.id=t_b.id)
    
    select * from t_a inner join t_b on(t_a.id=t_b.id)
    
    select * from t_a,t_b where t_a.id=t_b.id
    
    
    --删除有重复的SQL
    delete from t_a
    where name in (
        select max(name) from t_a group by id having count(name)>1
    )
    
    --游标
    
    declare @id int 
    declare f_cursor  cursor for select id from t_a 
    
    open f_cursor
    while @@fetch_status=0
    begin 
        fetch next from f_cursor into @id
        print @id
        print 'd'
    end
    close f_cursor
    deallocate f_cursor
  • 相关阅读:
    中缀表达式std
    后缀表达式
    取石头游戏
    LeetCode404Sum of Left Leaves左叶子之和
    LeetCode387First Unique Character in a String字符串中第一个唯一字符
    简单排列习题2.5 的 2
    周期串Uva455 P37 3-4
    【递归】分形
    【递归】普通递归关系(矩阵快速幂)
    P3486 [POI2009]KON-Ticket Inspector
  • 原文地址:https://www.cnblogs.com/xdpxyxy/p/3041363.html
Copyright © 2011-2022 走看看