zoukankan      html  css  js  c++  java
  • 数据检索

    --数据检索
    --给列换成一个别名 //as可省略
    select 列名1 as 别用名1,列名2 as 别用名2 from 表名
    select EmpGender as 性别 ,EmpDate as 日期 from Employer
    --distinct关键字,去除重复
    select distinct sName,sAge from Student
    -------------------------------------------------------------------------------------------

    --排序--order by
    select * from 表名 order by 列名 desc(降序)/asc(升序) --默认是升序排序
    --order by 与 top 连用
    --查询数学成绩最高的前五名
    select top 5 * from Student order by MathScore desc //top后可跟表达式,但是表达式必须用(),否则报错
    --查询数学成绩最高的前30%
    select top 30 percent * from Student order by MathScore desc

    -------------------------------------------------------------------------------------------
    --1.聚合函数 sum() --聚合函数不统计空值
    --统计所有人的年龄总和
    select sum(age) as 年龄总和 from person
    --统计当前表中共有多少条记录
    select count(*) from person
    --计算平均年龄
    select 平均年龄 = (select sum(age) as 年龄总和 from person) / select count(*) from person --竟然支持这样的格式书写???

    --计算年龄最大的
    select max(age) from person
    --计算年龄最小的
    select min(age) from person
    --计算平均年龄
    select avg(age) from person
    --2.如果数据列表没有分组(group by)的话,那么聚合函数会把表中的所有数据默认为一个分组

  • 相关阅读:
    HDU 5444 Elven Postman 二叉排序树
    HDU 5438 Ponds dfs模拟
    Gym
    markdown test
    Gym
    集训回顾
    UVALive
    UVALive
    UVALive
    codeforcres 589 J
  • 原文地址:https://www.cnblogs.com/decoct-tea/p/11321593.html
Copyright © 2011-2022 走看看