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

相关推荐
睡觉的时候不会困18 小时前
Redis 主从复制详解:原理、配置与主从切换实战
数据库·redis·bootstrap
程序员的世界你不懂19 小时前
【Flask】测试平台开发,新增说明书编写和展示功能 第二十三篇
java·前端·数据库
自学也学好编程19 小时前
【数据库】Redis详解:内存数据库与缓存之王
数据库·redis
JAVA不会写20 小时前
在Mybatis plus中如何使用自定义Sql
数据库·sql
IT 小阿姨(数据库)20 小时前
PgSQL监控死元组和自动清理状态的SQL语句执行报错ERROR: division by zero原因分析和解决方法
linux·运维·数据库·sql·postgresql·centos
ChinaRainbowSea20 小时前
7. LangChain4j + 记忆缓存详细说明
java·数据库·redis·后端·缓存·langchain·ai编程
小马学嵌入式~1 天前
嵌入式 SQLite 数据库开发笔记
linux·c语言·数据库·笔记·sql·学习·sqlite
Java小白程序员1 天前
MyBatis基础到高级实践:全方位指南(中)
数据库·mybatis
Monly211 天前
人大金仓:merge sql error, dbType null, druid-1.2.20
数据库·sql
不宕机的小马达1 天前
【Mysql|第一篇】Mysql的安装与卸载、Navicat工具的使用
数据库·mysql