-- 1. 查询学生表中的所有信息; 查询学生姓名
SELECT
*
FROM
student;
SELECT
sname
FROM
student;
-- 2.插入一行数据:
INSERT INTO student
VALUES
( "6", "田章", "男" );
INSERT INTO student
VALUES
( "7", "张章", "男" );
-- ** 插入一行中的指定列:
INSERT INTO student ( student_id, sname )
VALUES
( "5", "天意" ) ;
-- 3.根据学生姓名更新学生信息:
UPDATE student
SET student_sex = "男男",
student_id = 44
WHERE
sname = "田章" ;
-- 4.***根据学生 id 删除学生信息:
DELETE
FROM
student
WHERE
student_id = 44;
-- ***根据学生姓名删除学生信息:
DELETE
FROM
student
WHERE
sname = "张章";
-- 5. 分组查询:查询每个学生的总分
SELECT
ANY_VALUE(sname) as `name`,
ANY_VALUE(sum(score)) as sum
FROM
student
INNER JOIN score ON student.student_id = score.student_id
GROUP BY student.sname
ORDER BY sname;
!!!Navicat 5.7以下的版本分组存在歧义,查询字段需要加上 ANY_VALUE(sname)
分数就可以加一个 sum,求总和
---------------------------------------------------------------------------------------------------------------------------------
总结:要不断去敲代码 写SQL 发现错误,及时改正就有进步哒 ,不写不知道 一写就废!! 不能只看,不动手实操
20231208