sql操作数据库(2)--->DQL、数据库备份和还原

时间:2021-01-07 12:10:15   收藏:0   阅读:0

查询

在sql建议使用单词来表示逻辑运算 and or

? 操作:


-- 逻辑运算符  与或非

-- 查询历史成绩为80分和100分的同学  or
select * from student as s where s.history = 80 or s.history = 100;

-- 查询本班同学成绩在70分以上的    and
SELECT * from student as s where  s.math > 70 and s.history > 70;

-- 取非  !
SELECT * from student as s where  ! (s.math > 70 and s.history > 70);

??将查询出来的结果值内容,再按照性别进行分组,分组2组。

-- 将查询出来的结果值内容,再按照性别进行分组,分组2组。文综和是多少
-- 年龄大于18岁的
/*
	1.我想要什么样的结果值
    2. sql中需要有哪些条件
    3. 在sql都需要涉及到几张表
 
*/
SELECT
    s.gender,sum(s.history+s.geo+s.political) as 文综和   -- 查询出来需要展示的结果值
from
    student as s
WHERE 
     s.age > 18
GROUP BY
    s.gender

-- 统计成年人男女各多少个?
SELECT
   s.gender, count(s.gender) as 个数
FROM
   student as s
WHERE 
   s.age >=18
GROUP BY
   s.gender

having和where的区别

技术图片

还原:

技术图片

数据库表的约束

技术图片

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!