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 '湖南%';

相关推荐
万事大吉CC15 分钟前
SQL表设计与约束教程
数据库·sql
员大头硬花生30 分钟前
七、InnoDB引擎-架构-后台线程
java·数据库·mysql
Ryan ZX39 分钟前
etcd 高可用分布式键值存储
数据库·分布式·etcd
研究司马懿44 分钟前
【ETCD】ETCD——confd配置管理
数据库·golang·自动化·运维开发·etcd·argocd·gitops
..Cherry..44 分钟前
Etcd详解(raft算法保证强一致性)
数据库·算法·etcd
Tadas-Gao1 小时前
MySQL存储架构解析:从数据无序到索引艺术的演进
数据库·分布式·mysql·微服务·云原生·架构
ANGLAL2 小时前
17.MyBatis动态SQL语法整理
java·sql·mybatis
懒羊羊不懒@2 小时前
【MySQL | 基础】通用语法及SQL分类
数据库·oracle
llxxyy卢2 小时前
基于时间的 SQL 盲注-延时判断和基于布尔的 SQL 盲注
数据库·sql·oracle
Yeats_Liao3 小时前
时序数据库系列(六):物联网监控系统实战
数据库·后端·物联网·时序数据库