zoukankan      html  css  js  c++  java
  • mysql_DML_select_聚合join

    聚合函数:

    select avg(salary)//平均值

    from wsb;

    select sum(salary)//总和

    from wsb;

    select max(salary)//最大

    from wsb;

    select min(salary)// 最小

    from wsb;

    select count(*)// 统计多少数据   配合where salary>500;

    from wsb;

    分组:分别计算  group by

    select sex,count(*) 

    from wsb2 group by sex; group by后面不能有where只能用having

    where后面不能跟聚合函数having可以

    eg1:

    select a.Name,SUM(b.Grade)
    from students a ,Score b
    GROUP BY a.Id,b.Stu_id, a.Name
    HAVING SUM(b.Grade)>100;

    eg:

    select a.Name,SUM(b.Grade)
    from students a ,Score b
    GROUP BY a.Id,b.Stu_id
    HAVING a.Id=b.Stu_id;  having如果后面没有跟聚合函数 那么对应字段必须在group by中有相应字段 

    join:
    Left join:左连接, 连接两张表,以左边表的数据匹配右边表中的数据,如果左边
    表中的数据在右边表中没有,会显示左边表中的数据。
    Right join:右连接,连接两张表,以右边表的数据匹配左边表中的数据,如果左边
    表中的数据在左边边表中没有,会显示右边表中的数据。
    Inner join:内连接,连接两张表,匹配两张表中的数据,和前面两个不同的是只会
    显示匹配的数据。
    select a.name 学生姓名,b.score 学生成绩 from students a left join score b on
    a.id=b.student_id;
    select a.name 学生姓名,b.score 学生成绩 from students a right join score b on
    a.id=b.student_id;
    select a.name 学生姓名,b.score 学生成绩 from students a INNER join score b on
    a.id=b.student_id;
    select a.name 学生姓名,b.score 学生成绩 from students a,score b where
    a.id=b.student_id;
  • 相关阅读:
    GRIDVIEW鼠标移动行变色
    如何在网页中实现打字效果
    C#的6种常用集合类
    开发和使用Web用户控件
    C# DataGridView的常用用法
    SQL精妙语句
    Web 调试代理软件-Fiddler
    RegisterStartupScript和RegisterClientScriptBlock的用法
    简单地过一下五个控件(ScriptManager、ScriptManagerProxy、UpdatePanel、 UpdateProgress和Timer
    Android4.0 SDK功能详解
  • 原文地址:https://www.cnblogs.com/lingxia/p/5897229.html
Copyright © 2011-2022 走看看