-- 增,删,改 insert delete update
-- 增 必需向一切列添补数据,除了(自增列,有默许值列,许可为空)能够不添补
INSERT [INTO] 表(列列表) values (值列表)
-- 删
DELETE from 表[where 前提]
DELETE from student
-- 改
UPDATE 表 set 列 = 值,列 = 值 [where 前提]
update student set name = '张亮',set sex = '女' where studentno = '4'
-- 查询 隐约查询 分页
like between in is null
-- 查询 排序 分组 衔接
-- 排序 order by 默许是升序:asc 降序:desc
-- 按多个列来排序,先按第一个字段排序,在此基本上再按第二个字段举行排序.
select * from student order by age,studentno
-- 分组 聚合函数 sum avg max min count
select sum(age),avg(age),max(age),min(age) from student;
-- count 是统计有若干数据行,假如是统计某个列,则会疏忽列中的NULL值。
select count(email) from student
-- 统计有若干门生没有录入邮箱信息??
select count(*) from student where email is null
-- 分组,group by 是把数据举行分类再汇总,必需要合营聚合函数运用,
-- 症结点:按什么举行分组,用什么聚合函数举行统计。
-- 假如某个列出如今from症结字前,且没有包含在聚合函数中,则此列必需出如今group by 子句中
-- 统计每一个年级有若干门生?
select gradeId,count(*) from student group by gradeId
-- 统计每一个年级男女门生各有若干? 按年级和性别举行分组,用count函数
select gradeid,sex,count(*) from student group by sex,gradeId;
-- 统计每一个年级有若干课时?
select gradeid,sum(classHours) from subject group by gradeid
-- 统计每一个年级有若干课程?
select gradeid,count(*) from subject group by gradeid
-- 统计每一个门生的总效果和均匀效果?
select studentno,sum(result),avg(result) from score group by studentno
-- 衔接查询 内衔接 外衔接 交织衔接
-- 当数据来自两个或两个以上的表时,则才用衔接查询来完成。
-- where 前提是两个表的主键列相称。
select * from student s,grade g where s.gradeid=g.gradeid
-- 发起运用下面的写法,机能好一些。
select * from student s inner join grade g on s.gradeid=g.gradeid
-- 查询姓名,学号、课程名、分数 数据来自于3个表?
select name,s.studentno,subjectname,result from student s
inner join score c on s.studentno = c.studentno
inner join subject j on c.subjectno= j.subjectno
-- 外衔接 左外衔接 右外衔接
/* 左外衔接,在前面的表是主表,背面的表是子表,主表的数据悉数显现,
再用子表的数据举行添补,假如子表中没有对应的数据,则用NULL来添补 */
select * from student s
left join score c on s.studentno = c.studentno
-- 查询有哪些门生没有参加过测验,用左外衔接完成??
select * from student s
left join score c on s.studentno = c.studentno
where c.studentno is null
-- 查询哪些门生没有参加测验,用子查询完成??
-- 子查询的效果只能是返回一列值,返回的值假如有多个,就只能用in 不能用 =
select * from student where studentno
not in( select studentno from score)
以上就是在Mysql中对表做一些简朴的基本操纵内容,愿望对人人有协助。
相干文章:
MySql基本语法(进修笔记)_MySQL
相识mysql基本语法
以上就是mysql基本语法的细致内容,更多请关注ki4网别的相干文章!