阶段回顾:

1.mysql:文件管理软件
2.三部分:
  服务端
  sql语句
  客户端
3.客户端
  mysql
  navicat
4.授权操作
  用户操作
  授权操作
5.sql语句
  数据库操作
    create database xx default charset utf8;
    drop database xx;
  数据表
    列
      数字 decimal
      整数
      小数
      字符串
      时间 datatime
      其他:引擎,字符表,起始值
      主键,一个表只能有一个主键,非空且唯一,自增。主键索引。索引是加速查找
      唯一索引:独立存在,可以和外键联合起来,可以为空,有加速查找特性。
      外键:具有约束功能,解决重复文字的问题
        一对多
        一对一
        多对多:至少要3张表
      数据行:

        查
        in not in
        between and
        limit
        group by having
        order by
        like "%a"
        left join xx on 关系
        笛卡尔积关系
          a表三条数据:1 2 3
          select * from a as a1,a as a2;
          产生9条冗余数据:
          1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
        临时表:保持临时数据,将结果再进行操作

练习:

7.查找既选择课程1又选择课程2的学生ID与姓名
select * from score where course_id=1 and course_id=2;
同一列既是1又是2这么写有问题
select * from score where course_id=1 or course_id=2
select * from score where course_id=1 or course_id=2 group by student_id having count(student_id)>1;
select student_id from score where course_id=1 or course_id=2 group by student_id having count(student_id)>1;

select score.student_id,student.sname from score
left join student on score.student_id=student.sid
where course_id=1 or course_id=2 group by student_id having count(student_id)>1;

8.查询学过xx老师的所有课程,的学生学号,姓名
select * from course
left join teacher on course.tearch_id=teacher.tid
where teacher.tname="空空";

select * from course
left join teacher on course.tearch_id=teacher.tid
where teacher.tname="空空";

select student_id from score where course_id in
(
select cid from course
left join teacher on course.tearch_id=teacher.tid
where teacher.tname="空空"
)
group by student_id having count(course_id)=
(
select count(cid) from course
left join teacher on course.tearch_id=teacher.tid
where teacher.tname="空空"
)

10.查询成绩小于60的学生,的学生学号,姓名
select * from score
left join student on score.student_id=student.sid where score.number>60

select * from score
left join student on score.student_id=student.sid where score.number>60
group by student_id

select score.student_id,student.sname from score
left join student on score.student_id=student.sid where score.number>60
group by student_id

distinct可以分组去重,但是使用group by也可以去重,最好用group by,distinct效率不高
select distinct student_id from score
left join student on score.student_id=student.sid where score.number>60

最新文章

  1. git使用
  2. FineUI(专业版)新增 5 款 Metro 皮肤,邀您共赏!
  3. css3新增选择器
  4. Http基础
  5. DOM系列---DOM获取尺寸和位置
  6. dx wpf的各种坑
  7. [CentOS 7] 安装nginx第一步先搭建nginx服务器环境
  8. spring替代方法
  9. Linux下的Memcache安装
  10. [CentOS]CentOS/RedHat/Fedora的Proxy设定(yum,wget,,rpm)
  11. iOS 后台运行实现 --备用
  12. 搭建laravel5全面教学,爬坑(windows下)。
  13. SVN客户端--TortoiseSVN使用说明(转)
  14. 【angular】angular如何让传递变量参数+ng-change的使用
  15. Myeclipse快捷键集合
  16. BeautifulSoup4库
  17. 数据库 ACID
  18. 第二节 Python基础之变量,运算符,if语句,while和for循环语句
  19. 基于tiny4412的Linux内核移植 -- 设备树的展开【转】
  20. Electron学习(一)——— electron的安装

热门文章

  1. OpenMediaVault5.6(OMV) 安装omv-extras - 2022.1.12
  2. 基于Docker部署Dubbo+Nacos服务
  3. Python连接Hadoop-impala方法
  4. GPS地图生成04之数据预处理
  5. Reverse for 'blog_detail.html' not found.解决方法
  6. listview自定义适配器
  7. Office2021简体中文离线安装包下载地址合集,目前最全
  8. ROS1 Qt5 CMake基本配置
  9. 1487. 保证文件名唯一 (Medium)
  10. 【剑指Offer】【树】【双向链表】二叉搜索树与双向链表