sql多表查询

mysql> drop view if exists v_student;

mysql> select * from score;

mysql> select * from student limit 2,4;

mysql> select * from student

-> where department='英语系' or department='中文系';

mysql> select count(1) from student

-> group by department;

mysql> select max(grade),c_name '最高分' from score

-> group by c_name;

mysql> select c_name,grade from student join score on student.id=score.stu_id

-> where name='李广昌';

mysql> select student.*,score.* from student join score on student.id

-> =score.stu_id;

mysql> select name,sum(grade) '总成绩' from student join score on student.id=score.stu_id

-> group by name;

mysql> select department,round(avg(grade),2) '总成绩' from student join score on student.id=

score.stu_id

-> group by department;

mysql> select student.*,c_name,grade from student join score on student.id=

-> score.stu_id

-> where c_name='计算机' and grade<95;

mysql> select student.*,c_name,grade from student join score on student.id=

-> score.stu_id

-> where c_name='计算机'

-> order by grade desc;

mysql> select id from student union select stu_id from score;

mysql> select name,department,c_name,grade from student join score on student.id=score.stu_id

-> where name like '张%' or name like '王%';

mysql> select name,year(now())-birth '年龄',c_name,grade from student join score on student.

id=score.stu_id

-> where address like '湖南%';

相关推荐
梦影_1 小时前
MySQL进阶教程(五)—— SQL调优(下)
android·大数据·数据库·后端·sql·mysql·database
考虑考虑1 小时前
mariadb数据库
数据库·后端·mariadb
John_Hui3 小时前
Windows 10 安装版本:mysql-8.1.0-winx64.zip
数据库·windows·mysql
莫晓燚3 小时前
双机部署若依 (RuoYi‑Vue) 传统环境部署---实战
linux·运维·数据库·redis·mysql·nginx·ruoyi
updayday8544 小时前
客户附件不该发往旧邮箱,如何在发送前拦截 - Ping64 邮件安全管控
大数据·网络·数据库·安全·智能路由器
倔强的石头_4 小时前
连接异常排障手册:拒连、超时、认证失败、空闲断开
数据库
lhbweilai4 小时前
QT(了解各个控件和布局)上
数据库·qt
莫晓燚5 小时前
搭建Redis 主从复制---实战
数据库·redis·缓存
灵晔君5 小时前
【MySQL】数据库基础
数据库·mysql·adb
香蕉大香蕉(06敬畏市场)5 小时前
MySQL 单点详解(03)
java·数据库·mysql·面试·八股·大厂实习