zoukankan      html  css  js  c++  java
  • 潭州课堂25班:Ph201805201 MySQL第三课 (课堂笔记)

     单表查询:

      select * from

     select sname from stu;

    条件查询

    select sname from stu where sid=2;

    select sname from stu where sid>2;

    select sname from stu where sid!=2;

     查询时取别名,

    select sid as 学号,sname as 姓名 from stu;

     模糊查询,

    select * from stu where sname like '小%';    %  有多少相似查出多少,

    select * from stu where sname like '小_';      _  有几条线,查出几条,,

    select * from stu where sname like '小___';      _  有几条线,查出几条,,

    排序    order by  字段名

    select * from stu order by tzid 【asc】;    升

    select * from stu order by tzid desc;        降

    限制查询  limit

    select * from stu limit 3;         可以理解为第 0 条开始往下 3条,

     

    select * from stu limit 3,1    从第 3 条往下第 1 第,

    平均值:

    select avg(age) from dstu;      求培元年龄,

    sql> select round(avg(age)) from dstu;        四舍五入平均值,统计

     统计: 有几条数据

    select count(age) from dstu;

    求最大值 

    > select MIN(age) from dstu;

    求最小值

    select  MIN(age) from dstu;

    求和

    select  SUM(age)  from  dstu;

    分级查询GROOP  BY

    统计出现的次数,

    select count(*) from stu GROUP BY tzid;      可以看成是查询每个科目的报名人数,

    统计每个科目报名人数,

    select tzid,count(sid) from stu group by tzid;

       科目   学生人数        学生表         科目

     分组条件查询,having

    select tzid as 科目,count(sid) as 学生人数 from stu group by tzid having 学生人数=2;

    多表查询  (着想查询)

    select * from dstu where age > 19.5;

    子查询:

      一条语句结合两条语句,

    select * from dstu where age > (select avg(age) from dstu);

    着想查询:

      内连接 [INNER| CROSS] JOIN

    同时查询二个表,

    select * from tanzhou,stu;

    select * from stu inner join tanzhou;

     

    关联查询:

      select * from stu inner join tanzhou on tzid=sid;

    外连接 { LEFT| RIGHT } JOIN

    select * from stu left  join dstu on id = sid; 

    与内连接相比,可以显示所有学生,包括未选课的学生,

    作业;:

    查询学生详情表性别为男,并年龄大于18,

    select * from dstu where age>18 and sex='b';

     

    在此基础上查改名,..

     需求: 作为宿管,想知道学生的 ( 姓名, 年龄,性别,所属学

    select  name js from 表单名 where js between 70 and 90 ;

    找出分数在70到90的。

    补充

  • 相关阅读:
    【网络流24题----15】汽车加油行驶问题
    【网络流24题】最小路径覆盖问题
    网络流二·最大流最小割定理
    贪吃蛇
    【SCOI2008】着色方案
    DARK的锁链
    【NOIP2014】飞扬的小鸟
    [NOIP2012] 借教室
    [NOIP2012] 开车旅行
    [NOIP2012] 国王游戏
  • 原文地址:https://www.cnblogs.com/gdwz922/p/9256686.html
Copyright © 2011-2022 走看看