首页 > 其他分享 >Navicat

Navicat

时间:2022-11-28 20:59:19浏览次数:60  
标签:Navicat course teacher student where id select

可视化软件Navicat

可视化软件就是第三方开发的用来充当数据库客户端的软件,特点是操作界面简单快捷,其底层本质还是SQL
能够操作数据库的第三方可视化软件有很多,针对MySQL数据库最出名的就是Navicat

1.下载
    浏览器搜索Navicat进入官网直接下载
2.破解
    1.网上搜索注册码,淘宝购买注册码
    2.直接下载破解版(版本较老)
    3.网上搜索破解教程或破解软件
    ...
    ps:
        这里分享一下我的破解方法https://www.bilibili.com/read/cv16884052
        
3.常用操作
    创建库、表、记录、主键、外键
    根据已有数据库生成模型或直接使用模型创建表、记录等
    新建查询可以编写SQL语句,并自带提示功能
    SQL语句注释语法
    --、#、\**\
    运行、转储SQL文件
    ps:有些功能可能需要自己修改SQL预览

多表查询练习题

提前准备的数据库文件
链接:https://pan.baidu.com/s/1D7OeWo9NozF6KJQ2yKdu7Q
提取码:zyg1

1、查询所有的课程的名称以及对应的任课老师姓名
    1.确定使用到哪些表
        只有course表和teacher表
    2.确定多表查询的思路
        使用内连接
    SELECT cname,tname FROM course INNER JOIN teacher ON course.teacher_id=teacher.tid;
2、查询平均成绩大于八十分的同学的姓名和平均成绩
    1.确定要用到几张表
        student表、score表
    2.求学生平均成绩,按照学生分组然后取num的平均值
    SELECT
        student_id,
        avg(num) 
    FROM
        score 
    GROUP BY
        student_id 
    HAVING
        avg(num) > 80;
    3.使用内连接
    select student.sname,avg_num from student inner join (SELECT
        student_id,
        avg(num) as avg_num
    FROM
        score 
    GROUP BY
        student_id 
    HAVING
        avg(num) > 80) as t1 on student.sid=t1.student_id;
3、查询没有报李平老师课的学生姓名
    1.确定需要使用几张表
        teacher表、course表、score表,student表
    2.确定李平老师教授了那些课程
        select teacher.tname,course.cid,course.cname from teacher inner join course
        on teacher.tid=course.teacher_id where teacher.tname='李平老师';
    3.确定哪些学生选择了李平老师的课程
        select student_id from score where course_id in (select cid from course where 
        teacher_id=(select tid from teacher where tname='李平老师'))
    4.取个反确定哪些学生没有选择李平老师的课程
    select sname from student where sid not in (select student_id from score where course_id 
    in (select cid from course where teacher_id=(select tid from teacher where tname='李平老师')));
4、查询没有同时选修物理课程和体育课程的学生姓名
    1.确定需要使用几张表
        course表、student表、score表
    2.筛选物理和体育的课程id
    	select cid from course where cname in ('物理','体育');
    3.根据课程筛选出所有选择了物理和体育的学生id
    	select student_id from score where course_id in (select cid from course where cname 
         in ('物	理','体育')) group by student_id having count(course_id) = 1;
    4.利用子查询获取学生姓名
        select sname from student where sid in (select student_id from score where course_id 
        in (select cid from course where cname in ('物理','体育')) group by student_id 
        having count(course_id) = 1);

5、查询挂科超过两门(包括两门)的学生姓名和班级
    1.确定使用了哪些表
    student表、score表、class表
    2.筛选出挂科的数据
    	select * from score where num < 60;
    3.筛选出挂科超过两门的学生
    select student_id from score where num < 60 group by student_id having count(course_id) >=2;
    4.获取学生姓名和班级
    select sname,caption from student inner join class on student.class_id=class.cid 
    where student.sid in (select student_id from score where num < 60 group by 
    student_id having count(course_id) >=2);

标签:Navicat,course,teacher,student,where,id,select
From: https://www.cnblogs.com/zyg111/p/16933561.html

相关文章