您的位置:首页 > 健康 > 美食 > sql多表查询

sql多表查询

2024/10/7 2:24:24 来源:https://blog.csdn.net/2301_77321794/article/details/140617685  浏览:    关键词: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 '湖南%';

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com