mysql数据库-单表查询

笔记 / 2021-08-23

表结构

mysql> desc student;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id      | varchar(10) | YES  |     | NULL    |       |
| name    | varchar(20) | NO   |     |         |       |
| chinese | float       | NO   |     | 0       |       |
| english | float       | NO   |     | 0       |       |
| math    | float       | NO   |     | 0       |       |
+---------+-------------+------+-----+---------+-------+

insert

向指定表内插入一条记录

insert into student values(1,'jack',98,93,95);

插入部分字段

insert into tableName(field1,field2) values(field1_val,field2_val);
insert into student(id,name) values(1,'jack');

update

更新数据

update student 
	set name = 'tom'
	where name = 'jack';

delete

delete from student 
	where name = 'tom';

select

查询所有字段

select * from student;
  • select: 指定查询哪些列的数据
  • column: 指定列名
  • * 表示所有列
  • from 指定查询哪个表
  • DISTINCT 可选(去掉重复数据)

查询学生姓名和英语成绩

select name,english from student;

取消重复数据

  • distinct
    只有每个字段相同才会去除
select distinct english from student;