单表查询语法:

SELECT 字段1,字段2... FROM 表名
                  WHERE 条件
                  GROUP BY field
                  HAVING 筛选
                  ORDER BY field
                  LIMIT 限制条数

关键字的执行顺序:

这个是非常重要的,不了解以后会有很多坑。

1.form        找到表:from

2.where        拿着where指定的约束条件,去文件/表中取出一条条记录

3.group by    将取出的一条条记录进行分组group by,如果没有group by,则整体作为一组

4.having        将分组的结果进行having过滤

5.select        执行select

6.distinct        去重

7.order by     将结果按条件排序:order by

8.limit        限制结果的显示条数

建立一个名为student的学生表,下面是他们的字段名及字段类型表。

数据库——MySQL——单表查询

create table student(
id int not null unique auto_increment,
name varchar(20) not null,
sex enum('male','female') not null default 'male',
age int(3) unsigned not null default 28,
birthday date not null,
class_id int
);
建表代码

相关文章:

  • 2022-02-09
  • 2021-06-12
  • 2021-05-26
  • 2022-12-23
  • 2023-03-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-24
  • 2021-10-26
  • 2022-12-23
  • 2021-06-05
  • 2021-12-06
相关资源
相似解决方案