zoukankan      html  css  js  c++  java
  • SQL server 常用语句

    记录一些简单常用的sql语句

    一、查询组

    表中结构与数据

    1、查询所有结果:select * from Test_Table

    结果:

    2、查询单独一列:select Test1 from Test_Table

    3、按条件查询:select Test1 from Test_Table where ID=1

     4、插入一行数据:insert into Test_Table values (4,'test11','test12','test13')

                      

            执行结果                                                       查询结果

    5、更新数据:update Test_Table set Test3='test14' where Test1='test11'

                           

                  执行结果                                                                 查询结果

    6、给列起别名:select ID AS '编号',Test1 as '第一列',Test2 as '第二列',Test3 as '第三列' from Test_Table

    7、新添加一列:alter Table Test_Table add Test4 int                

                                  注:最后int 为Test4的字段类型

         

                        执行结果                                                                       重新查询

    8、批量循环更新数据:

    declare @i int  
    set @i=0
    while @i<5
    begin
        update Test_Table set Test4 = @i+5 
        set @i=@i +1
    end

                        执行结果                                                                                查询结果

    二、数据操作

    表中的元数据为:

    1、替换查询结果中的数据

    select ID,Test4=
    case  
         when Test4<60  then '未及格' 
         when Test4>=60 and Test4<90  then '合格'
         else '优秀' 
         end 
    from Test_Table

     执行结果如下:

     2、求最大数:select max(Test4) from Test_Table

    3、求最小数:select min(Test4) from Test_Table

    4、求平均数:select avg(Test4) from Test_Table

    5、求和:select sum(Test4) from Test_Table

    6、统计满足条件的行数:select count(*) from Test_Table where Test4>60

    狼的性格,羊的行为
  • 相关阅读:
    【转】 【技巧 】 数学难题大揭秘:减少计算错误的技术
    [转]Mathematical Induction --数学归纳法1
    Vector Calculus
    test latex1
    [转]架构蓝图--软件架构 "4+1" 视图模型
    What Is Mathematics?
    二项式展开
    游戏系统设计
    Golang游戏服务器与skynet的个人直观比较
    [转]透过 Linux 内核看无锁编程
  • 原文地址:https://www.cnblogs.com/sunjianping/p/11163990.html
Copyright © 2011-2022 走看看