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

相关推荐
jjkkzzzz2 小时前
Linux下的c/c++开发之操作Redis数据库
数据库·c++·redis
老华带你飞3 小时前
实习记录小程序|基于SSM+Vue的实习记录小程序设计与实现(源码+数据库+文档)
java·数据库·spring boot·小程序·论文·毕设·实习记录小程序
Elastic 中国社区官方博客4 小时前
Elasticsearch 索引副本数
大数据·数据库·elasticsearch·搜索引擎·全文检索
冬瓜的编程笔记4 小时前
【八股战神篇】MySQL高频面试题
数据库·mysql·面试
赵渝强老师5 小时前
【赵渝强老师】Memcached的路由算法
数据库·redis·nosql·memcached
belldeep5 小时前
groovy 如何遍历 postgresql 所有的用户表 ?
数据库·postgresql
2401_896008195 小时前
PostgreSQL
数据库·postgresql
搞不懂语言的程序员5 小时前
Redis Sentinel如何实现高可用?
数据库·redis·sentinel
wangzhongyudie5 小时前
SQL实战:06交叉日期打折问题求解
数据库·sql