MySQL连表查询

MySQL多表操作:

  以学生表、成绩表和考勤表为例:

  1、创建数据库:

    create database 数据库;

  连表学生总成绩降序排列:

    select score.g_id,student.name,score.total from student,score where score.s_id=student.s_id order by score.total desc;

  从成绩表中和学生表中找总成绩最高的学生:

  select 成绩表.g_id,学生表.name,成绩表.total from 学生表 inner join 成绩表 on 学生表.s_id=成绩表.s_id group by 学生表.s_id order by max(成绩表.total) desc limit 1;
  select score.g_id,student.name,score.total from student,score where score.s_id=student.s_id order by score.total desc limit 1;
原文地址:https://www.cnblogs.com/xiaozhou223/p/11824195.html