zoukankan      html  css  js  c++  java
  • 第二章 数据的查询

    --1.查询所有列
    select * from Student 
    --2.查询一个表中的指定的列
    select 姓名, 总学分 from Student 
    --3.定义列别名
    select 姓名 as xm , 总学分 as zxf from Student
    --4.替换查询结果中的数据
    select 姓名,
    case when 总学分<50 then '不及格'
    when 总学分<52 then '合格'
    else '优秀' 
    end as 等级
    from Student
    --5.计算列
    select 学号, 姓名,出生时间,YEAR(getdate())-YEAR(出生时间) as 年龄 from Student 
    --6.消除重复行
    select distinct 专业 from Student
    --7.前6行的数据
    select top 6 * from Student 
    --8.对查询结果的排序
    select * from Student order by 出生时间 asc
    select * from Student order by 出生时间 desc
    --聚合函数
    select sum(总学分) from Student
    select max(总学分) from Student
    select min(总学分 )from Student
    select avg(总学分) from Student 
    select count(*) from Student 
    --where 子句
    select * from Student where 性别=''
    select * from Student where 专业='通信工程'and 总学分>=42
    --模糊查询
    select * from Student where 姓名 like '王%'
    select * from Student where 姓名 like '王_'
    --范围比较
    select * from Student where 出生时间>='1990-1-1'and 出生时间<='1995-12-31'
    select * from Student where 出生时间 between '1990-1-1'and '1995-12-31'
    select * from Student where 专业 in('计算机','通信工程')
    --空值比较
    select * from Student where 备注=''
    select * from Student where 备注 is null
    
    
     
  • 相关阅读:
    苏宁易购积分规则
    购物车的实现原理
    <mvc:annotation-driven />讲解
    c3p0、dbcp和proxool比较
    Spring的事务到底该给Dao配置还是给Service配置?
    Spring PropertyPlaceholderConfigurer占位符用法
    Spring <context:annotation-config />讲解
    DispatcherServlet讲解
    Spring3.1新特性
    Spring MVC入门
  • 原文地址:https://www.cnblogs.com/zhang1997/p/7840063.html
Copyright © 2011-2022 走看看