mysql进阶:查询,联表查询,汇聚查询

统计:

# 统计所有年龄为19岁的学生数量
  select count(*) from t_student_info where age = 19;
# 统计学校男女老师的数量
  select count(gender), gender from t_teacher group by gender;

联表查询:

# 查询分数表中所有年龄大于等于18岁的学生的详细(姓名,年龄,性别)信息和分数以及对应的课程
  select stu.sname, stu.age, stu.sex, score.score, cou.cname, cou.course_no 
  from t_student_info stu join t_score score on stu.stuno = score.stuno
  join t_course cou on score.course_no = cou.course_no
  where stu.age >= 18;

# 查询所有年龄大于20岁的 理工农学院的老师信息
  alter table t_teacher add column age int(3) not null comment '年龄';
  select * from t_teacher join t_department on t_teacher.department = t_department.dept_no where age > 20;
  

汇聚查询:

# 汇聚查询
# 将老师和学生的信息进行聚合显示
select tname, age, gender from t_teacher union select sname, age, sex from t_student_info limit 100;
  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值